ecabrera Posted January 4, 2012 Share Posted January 4, 2012 is it possible to use the while out side the php for ex. <?php require "scripts/connect.php"; $query = mysql_query("SELECT * FROM news WHERE section='gtkphp'"); while($rows = mysql_fetch_assoc($query)){ $id = $rows['id']; $title = $rows['title']; $body = $rows['body']; } mysql_close(); ?> make eache like have its own id number <a href="view.php?='<?php echo $id;?>"></a> <a href="view.php?='<?php echo $id;?>"></a> <a href="view.php?='<?php echo $id;?>"></a> Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/ Share on other sites More sharing options...
trq Posted January 4, 2012 Share Posted January 4, 2012 You need to have this: <a href="view.php?='<?php echo $id;?>"></a> <a href="view.php?='<?php echo $id;?>"></a> <a href="view.php?='<?php echo $id;?>"></a> within your loop. Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304310 Share on other sites More sharing options...
ecabrera Posted January 4, 2012 Author Share Posted January 4, 2012 say i have a table wounld'nt this mulitple Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304312 Share on other sites More sharing options...
trq Posted January 4, 2012 Share Posted January 4, 2012 What? Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304317 Share on other sites More sharing options...
ecabrera Posted January 4, 2012 Author Share Posted January 4, 2012 say i want them to be should inside a table how would i do that so the table dose not multiple <table> <tr> <td> <a href="view.php?='<?php echo $id;?>"></a> <a href="view.php?='<?php echo $id;?>"></a> <a href="view.php?='<?php echo $id;?>"></a> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304319 Share on other sites More sharing options...
trq Posted January 4, 2012 Share Posted January 4, 2012 <table> <?php while($rows = mysql_fetch_assoc($query)) {?> <tr> <td> <a href="view.php?='<?php echo $id;?>"></a> <a href="view.php?='<?php echo $title;?>"></a> <a href="view.php?='<?php echo $body;?>"></a> </td> </tr> <?php } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304321 Share on other sites More sharing options...
ecabrera Posted January 4, 2012 Author Share Posted January 4, 2012 nope <?php require "scripts/connect.php"; $query = mysql_query("SELECT * FROM news WHERE section='gtkphp'"); $id = $rows['id']; $title = $rows['title']; $body = $rows['body']; ?> <table> <?php while($rows = mysql_fetch_assoc($query)) {?> <tr> <td> <a href="view.php?=<?php echo $id;?>"><?php echo $title;?></a> <a href="view.php?=<?php echo $id;?>"><?php echo $title;?></a> </td> </tr> <?php } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304323 Share on other sites More sharing options...
trq Posted January 4, 2012 Share Posted January 4, 2012 Explain "nope" I'm not a mind reader. Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304324 Share on other sites More sharing options...
ecabrera Posted January 4, 2012 Author Share Posted January 4, 2012 sorry , the id is the same as the other and the title to Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304326 Share on other sites More sharing options...
trq Posted January 4, 2012 Share Posted January 4, 2012 Your echoing the same links twice. <a href="view.php?=<?php echo $id;?>"><?php echo $title;?></a> <a href="view.php?=<?php echo $id;?>"><?php echo $title;?></a> How do you want the table to display? Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304327 Share on other sites More sharing options...
ecabrera Posted January 4, 2012 Author Share Posted January 4, 2012 i want the table to be one table and inside the table mutiple links that take you to a diffrent page for example <a href="view.php?=1">name1</a> <a href="view.php?=2">name2</a> <a href="view.php?=3">name3</a> Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304330 Share on other sites More sharing options...
trq Posted January 4, 2012 Share Posted January 4, 2012 <table> <?php while($rows = mysql_fetch_assoc($query)) {?> <tr> <td> <a href="view.php?=<?php echo $id;?>"><?php echo $title;?></a> </td> </tr> <?php } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304333 Share on other sites More sharing options...
ecabrera Posted January 4, 2012 Author Share Posted January 4, 2012 does not work i have this <?php require "scripts/connect.php"; $query = mysql_query("SELECT * FROM news WHERE section='gtkphp'"); while($rows = mysql_fetch_assoc($query)) { $id = $rows['id']; $title = $rows['title']; $body = $rows['body']; } ?> <table> <?php while($rows = mysql_fetch_assoc($query)) {?> <tr> <td> <a href="view.php?=<?php echo $id;?>"><?php echo $title;?></a> </td> </tr> <?php } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304336 Share on other sites More sharing options...
trq Posted January 4, 2012 Share Posted January 4, 2012 Look at your logic. <?php require "scripts/connect.php"; $query = mysql_query("SELECT * FROM news WHERE section='gtkphp'"); <table> <?php while($rows = mysql_fetch_assoc($query)) { $id = $rows['id']; $title = $rows['title']; $body = $rows['body']; ?> <tr> <td> <a href="view.php?=<?php echo $id;?>"><?php echo $title;?></a> </td> </tr> <?php } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304338 Share on other sites More sharing options...
ecabrera Posted January 4, 2012 Author Share Posted January 4, 2012 this doesn't work at all Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304343 Share on other sites More sharing options...
trq Posted January 4, 2012 Share Posted January 4, 2012 A few simple errors. I was missing a closing php tag. Are you even trying to do this yourself? <?php require "scripts/connect.php"; $query = mysql_query("SELECT * FROM news WHERE section='gtkphp'"); ?> <table> <?php while($rows = mysql_fetch_assoc($query)) { $id = $rows['id']; $title = $rows['title']; $body = $rows['body']; ?> <tr> <td> <a href="view.php?=<?php echo $id;?>"><?php echo $title;?></a> </td> </tr> <?php } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304347 Share on other sites More sharing options...
ecabrera Posted January 4, 2012 Author Share Posted January 4, 2012 thorpe trust me i am trying Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304348 Share on other sites More sharing options...
PaulRyan Posted January 4, 2012 Share Posted January 4, 2012 This may seem off topic, but why don't people look at the code given and try it for themselves? It really irates me when people expect the code you post to work exactly as they want it, and then when it doesn't they don't even try to fix it. Simply looking at the code highlighting would should you that the ending PHP tag was missing, or am I just nit picking here? Regards, PaulRyan. Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304349 Share on other sites More sharing options...
ecabrera Posted January 4, 2012 Author Share Posted January 4, 2012 PaulRyan im sorry you fill that way but i did try maybe my eyes didnt pick it up i was thinking on what other solution their was im human no a robot and thorpe thanks Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304350 Share on other sites More sharing options...
PaulRyan Posted January 4, 2012 Share Posted January 4, 2012 It wasn't a personal attack on you Ecabrera, it just happened to be this thread that cross the line for me. Quote Link to comment https://forums.phpfreaks.com/topic/254373-use-their-own-id/#findComment-1304354 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.