Re: PHP and MySQL Problem (simple, I'm sure)

From: Date: Sun, 22 Oct 2000 17:51:05 +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-21648@lists.php.net to get a copy of this message
Also, if you are selecting all columns from a table, you don't have to use "SELECT id, seating, blah, blah, blah..." You could more easily just say $query = "select * from spas order by price desc"; $result = mysql_query($query) or die ("MySQL reported an error: " . mysql_error()); while ($row = mysql_fetch_array($result)) { extract($row); # code that will execute for every row returned goes here }; # or you can just pull out the variables using extract() and put code that will only execute once here The die() function in the above code will also help you troubleshoot things when you, say, select from a table which doesn't exist. Experiment with it until you find something that works well for you. Erica "Ben Ocean" <lists@TheWebsons.com> wrote in message news:5.0.0.25.0.20001022080414.00a29270@thewebsons.com... > 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 >

« previous php.general (#21648) next »