Lustat Posted April 7, 2010 Share Posted April 7, 2010 I'm having issues with displaying data from mysql into a table. basically I want to auto generate the data and insert it into a left column, than the next set into a right column and so on down the page. my current coding that I tried is <?php$i=0;while ($i < $num) {$f1=mysql_result($result,$i,"shop_name");$f2=mysql_result($result,$i,"shop_address");$f3=mysql_result($result,$i,"shop_zip");$f4=mysql_result($result,$i,"shop_hours");$f5=mysql_result($result,$i,"shop_tel");?> <table width="100%"><tr> <td width="50%"><b><?PHP echo $f1; ?></b><br><?PHP echo $f2; ?><br><?PHP echo $f3; ?><br><?PHP echo $f4; ?><br><?PHP echo $f5; ?><br><br> </td> <td width="50%"><b><?PHP echo $f1; ?></b><br><?PHP echo $f2; ?><br><?PHP echo $f3; ?><br><?PHP echo $f4; ?><br><?PHP echo $f5; ?><br><br> </td></tr></table> but this just repeats the exact same info in both columns all the way down the page. any ideas how to fix this ?thanks in advance Link to comment Share on other sites More sharing options...
justsomeguy Posted April 8, 2010 Share Posted April 8, 2010 Where does the while loop end? Are you incrementing $i each time through the loop? Is the problem that all rows have the same data? Link to comment Share on other sites More sharing options...
Lustat Posted April 8, 2010 Author Share Posted April 8, 2010 Where does the while loop end? Are you incrementing $i each time through the loop? Is the problem that all rows have the same data?I didnt set an end to it, just looks for all rows where one of the columns equals the cookie that was set. my code is $query = "SELECT shop_state, shop_name, shop_address, shop_zip, shop_hours, shop_tel, shop_url FROM shopsdb WHERE shop_state = '$state'"; $result = mysql_query($query) OR die(mysql_error()); if (mysql_num_rows($result) != 1) { }} else {}$row = mysql_fetch_assoc($result); $num=mysql_numrows($result); what the original code that I have above does, is it makes 2 columns and both left and right column have the exact same data all the way downrow 1 | row 2data1 | data1data2 | data2and I want it to bedata1 | data2data3 | data4 Link to comment Share on other sites More sharing options...
justsomeguy Posted April 8, 2010 Share Posted April 8, 2010 The while loop needs an ending, if you don't have a closing bracket that's going to be a syntax error. I assume you're also incrementing $i at some point in the loop, but I don't see that either. It should be obvious why it's printing the same information though: <table width="100%"><tr> <td width="50%"><b><?PHP echo $f1; ?></b><br><?PHP echo $f2; ?><br><?PHP echo $f3; ?><br><?PHP echo $f4; ?><br><?PHP echo $f5; ?><br><br> </td> <td width="50%"><b><?PHP echo $f1; ?></b><br><?PHP echo $f2; ?><br><?PHP echo $f3; ?><br><?PHP echo $f4; ?><br><?PHP echo $f5; ?><br><br> </td></tr></table> You're just printing the variables once, then you're printing the same variables again without changing them. It should be obvious that that's going to print the same data both places. If you want to print different values the second time then you need to change the variables. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.