teknospr Posted March 7, 2011 Share Posted March 7, 2011 Good day: Im trying to get a numer from a table and use it to know how many pages are in the article so the script knows how many hyperlinks for the pages to generate (ex. links for pages 1 to 5). This is the script so far: <?php $aid = $_GET['aid']; $sd = $_GET['sd']; $connection = mysql_connect("localhost", "username", "password"); mysql_select_db("articles", $connection); $query="SELECT pages FROM articles_description WHERE articleid=$sd"; $result=mysql_query($query); $num=$result; mysql_close(); ?> <table width ="600" border="0" cellspacing="2" cellpadding="2" align="center"> <th><font face="Arial, Helvetica, sans-serif">pages</font></th> <?php $i=1; while ($i <= $num) { ?> <td align="center"><font face="Arial, Helvetica, sans-serif"><?php echo "<a href=\"$f3?aid=$aid&sd=$i\" target=\"_self\">$i</a>"; ?></font></td> </td> <?php $i++; } ?> Any help will be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/229917-using-a-numer-in-a-table-for-a-loop/ Share on other sites More sharing options...
sasa Posted March 7, 2011 Share Posted March 7, 2011 you mean $num=mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/229917-using-a-numer-in-a-table-for-a-loop/#findComment-1184221 Share on other sites More sharing options...
teknospr Posted March 7, 2011 Author Share Posted March 7, 2011 Sorry about the question, but inst that the amount of rows? Or is it the number that is stored in the table? Im trying to retrieve the number in the table which is where the amount of pages of the article is stored. Quote Link to comment https://forums.phpfreaks.com/topic/229917-using-a-numer-in-a-table-for-a-loop/#findComment-1184224 Share on other sites More sharing options...
sasa Posted March 7, 2011 Share Posted March 7, 2011 OK then use $num=mysql_result($result, 0, 0); Quote Link to comment https://forums.phpfreaks.com/topic/229917-using-a-numer-in-a-table-for-a-loop/#findComment-1184230 Share on other sites More sharing options...
teknospr Posted March 7, 2011 Author Share Posted March 7, 2011 It worked. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/229917-using-a-numer-in-a-table-for-a-loop/#findComment-1184237 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.