itsureboy Posted July 13, 2007 Share Posted July 13, 2007 Ok Heres my problem. I am fetching data from my database and displaying 1 result per table for example: 1 result(<-looping this) 2 result 3 result What i want to do is display 2 results in a table and loop that for example: 1 result - 2 result(<-looping this) 3 result - 4 result 5 result - 6 result the problem is the variable will be assinged the same thing so i wouldnt be able to do that. What i want to know is how i would be able to do what i said above. Sorry if this doesnt make sense.... Here is my code: <?php include 'exampleconnect.php'; if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 12; $cat = $cat; $from = (($page * $max_results) - $max_results); $sql = mysql_query("SELECT title, image FROM rap WHERE category = '$cat' ORDER BY id DESC LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)){ echo $row['title']; echo $row['image']; } include 'exampleclose.php'; Thanks... Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 13, 2007 Share Posted July 13, 2007 more explanation plsss Quote Link to comment Share on other sites More sharing options...
itsureboy Posted July 13, 2007 Author Share Posted July 13, 2007 Lol ok... For example I am displaying 1 product per table on my website thats being looped displaying a bunch of tables displayed vertically. What I want to do know is embed 2 tables in a table (two products in that main table) and loop that. But if i do that it will display the same product(2 products) in that *Main Table* because the variable is assigned the same value. So in that loop i want to make the variables switch to the next row in the same loop. Hopes this is better. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 13, 2007 Share Posted July 13, 2007 are you saying you get another data from another table? then you have to use join or if not use the loop within the loop tell me which of the two and i will explain more Quote Link to comment Share on other sites More sharing options...
itsureboy Posted July 13, 2007 Author Share Posted July 13, 2007 Oh you could use a loop within a loop. I didn't know that. If its not a problem can i get an example please. I thinks thats what i need. Thanks.... Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 14, 2007 Share Posted July 14, 2007 just an idea while($row = mysql_fetch_array($sql)){ echo $row['title']; echo $row['image']; if (put the condition here) { //put here another query if thats what you mean while($row2 = mysql_fetch_array($sql2)){ //do somwthing here } } } Quote Link to comment Share on other sites More sharing options...
Barand Posted July 14, 2007 Share Posted July 14, 2007 try something like this <?php include 'db.php'; define ("NUMCOLS",2); $res = mysql_query("SELECT col1, col2 FROM mytable"); $count = 0; echo "<TABLE border=1>"; while (list($col1, $col2) = mysql_fetch_row($res)) { if ($count % NUMCOLS == 0) echo "<TR>\n"; # new row echo "<TD>$col1<br>$col2</TD>\n"; $count++; if ($count % NUMCOLS == 0) echo "</TR>\n"; # end row } # end row if not already ended if ($count % NUMCOLS != 0) { while ($count++ % NUMCOLS) echo "<td> </td>"; echo "</TR>\n"; } echo "</TABLE>"; ?> Quote Link to comment Share on other sites More sharing options...
itsureboy Posted July 14, 2007 Author Share Posted July 14, 2007 I tried both of those and i did'nt work.... I'll give it one more shot at explaining it. (INFO IS IN THE CODE BOX) <?php include 'exampleconnect.php'; if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 12; $cat = $cat; $from = (($page * $max_results) - $max_results); $sql = mysql_query("SELECT title, image FROM rap WHERE category = '$cat' ORDER BY id DESC LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)){ echo $row['title']; echo $row['image']; ##I want to use $row['image'] again in this loop but with the value of the next row in the database (same query) } include 'exampleclose.php'; Quote Link to comment Share on other sites More sharing options...
itsureboy Posted July 14, 2007 Author Share Posted July 14, 2007 I want to use $row['image'] again in that same loop but with the value of the next row in the database (same query) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.