Re: PHP and MySQL Problem (simple, I'm sure)
| From: | Steve Lawson | Date: | Sun, 22 Oct 2000 15:50:40 +0000 |
| Subject: | Re: PHP and MySQL Problem (simple, I'm sure) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-21641@lists.php.net to get a copy of this message | ||
Yo,
Are you sure you connected the database? That sounds like the error I
get when I forget to connect.
Also, I believe num rows is mysql_num_rows() not mysql_numrows();
You should be using mysql_fetch_array(); mysql_result() is extremely slow,
especially for such a large result set.
After your query...do this:
while($row = mysql_fetch_array($result))
{
extract($row);
echo "This tub has $filtration filtration, $water_care water_care, and
costs $price dollars<BR>\n";
// more code here...
}
The while will execute as long as it has rows to fetch. mysql_fetch_array()
will return an assoc array like so $row["column_name"] = value;
echo $row["header"]; // displays the value in header.
Although, most of us find this a hassle when outputting lots of variables in
strings.... So, I use the extract() command. extract() takes that assoc
array and makes the keys into normal variables.
$row["header"] becomes $header;
This way out can just output the values right in the string without having
to end and start the string
like:
echo "This is a value $column_name<BR>\n";
instead of:
echo "This is a value: " . $row["column_name"] . "<BR>\n";
Hope that helps.
----- Original Message -----
From: "Ben Ocean" <lists@TheWebsons.com>
To: <php-general@lists.php.net>
Sent: Sunday, October 22, 2000 9:10 AM
Subject: [PHP] PHP and MySQL Problem (simple, I'm sure)
> Hi;
> I'm taking a script I wrote that worked for one client and trying to tweak
> it for another client. These clients are built on the same server. I have
> run into this error message:
>
> Warning: 0 is not a MySQL result index in
>
/apache/vhosts/thewebsons/Clients/NWHotSpring/Spas/Find_the_Perfect_Spa/inde
x.php3
> on line 81
>
> Here is the script circa line 81...
>
> if ($colorz != 9 ) { // ADD THIS LATER && $seatingz !=9 && $typez
> != 9) {
> echo "<center><font style=\"font: 800 25px
> futura\">Here's Your
> Spas!</font></center>";
> echo "Click on any spa.";
> /* LINE 80 */ $result = mysql_query("SELECT id, seating,
color_one,
> color_two, color_three, type, name, jets, jets_one, jets_two, jets_three,
> jets_four, jets_five, jets_six, jet_system, dimensions, capacity, dry,
> filled, light, control, heater, thermostat, jetPumps, circulationPump,
> filter, filtration, water_care, price FROM spas ORDER BY price DESC");
> $total_rows = mysql_numrows($result); $counter = 0; $countertwo =
0;
> while($counter < $total_rows):
> do a bunch of stuff...
>
> Can someone please help me?
>
> Also, I'm wondering if there's a more elegant way to label variables than
this:
> $seatingee = mysql_result($result,$counter,"seating");
> If I don't need *seating* any more, can I simply call the result
*$seating*
> instead of *$seatingee* ?
> TIA,
> BenO
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>