Vizonz Posted June 28, 2010 Share Posted June 28, 2010 $num=mysql_num_rows($result); mysql_close(); ?> <table border="0" cellspacing="2" cellpadding="2> <? $i=0; while ($i < $num) { $title=mysql_result($result,$i,"title"); $writer=mysql_result($result,$i,"writer"); $link=mysql_result($result,$i,"link"); ?> <tr> <td><b>book</b>: <a href="<? echo "$title"; ?>"><? echo "$writer"; ?></a> <br /><? echo "$link"; ?><br /></td> </tr> </tr> <? ++$i; } echo "</table>"; ?> okay in this code i am getting results but the problem which i dont know how to fix is when it shows the last ten results. the first record at the top loses any html added like the rest of them will have the link but the top record wont. example book title - author link book title - author LINK and how do i get it to display a count. 1. 2. 3. 4. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 28, 2010 Share Posted June 28, 2010 Please show more of your code, i.e. from the query statement on. Ken Quote Link to comment Share on other sites More sharing options...
Vizonz Posted June 28, 2010 Author Share Posted June 28, 2010 okay i have to actually post the code that was just a edited version $query = "SELECT DISTINCT requestlist.songID, requestlist.msg, requestlist.name, requestlist.status, songlist.ID, requestlist.ID, songlist.artist, songlist.title, songlist.count_requested, songlist.composer FROM radio.requestlist INNER JOIN radio.songlist ON requestlist.songID = songlist.ID WHERE requestlist.status = 'played' ORDER BY songlist.last_requested DESC LIMIT 5; "; $result=mysql_query($query); $num=mysql_num_rows($result); mysql_close(); ?> <table border="0" cellspacing="2" cellpadding="2> <? $i=0; while ($i < $num) { $name=mysql_result($result,$i,"name"); $artist=mysql_result($result,$i,"artist"); $title=mysql_result($result,$i,"title"); $msg=mysql_result($result,$i,"msg"); $composer=mysql_result($result,$i,"composer"); ?> <tr> <td><b>Song</b>: <a href="<? echo "$composer"; ?>"><? echo "$artist"; ?></a> - <? echo "$title"; ?><br /><b>Dedicated By</b>:<? echo "$name"; ?><br /><b>Dedication</b>:<? echo "$msg"; ?><br /></td> </tr> </tr> <? ++$i; } echo "</table>"; ?> i am new to this all so if the queries could be written better please help there as well Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 28, 2010 Share Posted June 28, 2010 For your first problem, you're missing a double quote on this line: <table border="0" cellspacing="2" cellpadding="2> This makes the browser suck up everything until it sees an '">', so you lose the formating. You probably would have seen this if you had looked at the generated source. Second, I would get rid of the mysql_close() function, it is not needed, since PHP will close the MySQL connection when it ends. I would also change your loop to use the mysql_fetch_assoc function: <?php $result=mysql_query($query); $num=mysql_num_rows($result); echo '<table border="0" cellspacing="2" cellpadding="2">'; while ($row = mysql_fetch_assoc($results)) { echo "<tr>\n"; echo '<td><b>Song</b>: <a href="{$row['composer']}">{$row['artist']}</a> - {$row['title']}<br /><b>Dedicated By</b>:{$row['name']}<br /><b>Dedication</b>:{$row['msg']}<br /></td>' . "\n"; echo "</tr>\n"; } echo "</table>"; ?> Ken Quote Link to comment Share on other sites More sharing options...
Vizonz Posted June 28, 2010 Author Share Posted June 28, 2010 where would the code you put start ? i tried to add it and it gave me some errors Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 28, 2010 Share Posted June 28, 2010 Here's you're whole snippet re-written: <?php $query = "SELECT DISTINCT requestlist.songID, requestlist.msg, requestlist.name, requestlist.status, songlist.ID, requestlist.ID, songlist.artist, songlist.title, songlist.count_requested, songlist.composer FROM radio.requestlist INNER JOIN radio.songlist ON requestlist.songID = songlist.ID WHERE requestlist.status = 'played' ORDER BY songlist.last_requested DESC LIMIT 5; "; $result=mysql_query($query); $num=mysql_num_rows($result); echo '<table border="0" cellspacing="2" cellpadding="2">'; while ($row = mysql_fetch_assoc($results)) { echo "<tr>\n"; echo '<td><b>Song</b>: <a href="{$row['composer']}">{$row['artist']}</a> - {$row['title']}<br /><b>Dedicated By</b>:{$row['name']}<br /><b>Dedication</b>:{$row['msg']}<br /></td>' . "\n"; echo "</tr>\n"; } echo "</table>"; ?> Note: I haven't checked the code for syntax errors. Ken Quote Link to comment Share on other sites More sharing options...
Vizonz Posted June 28, 2010 Author Share Posted June 28, 2010 Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in on line 18 sorry about probably simple things to fix but i am still learning and as i look at the code i dont understand this $num=mysql_num_rows($result); $num= is tthat not a variable ? so why when your calling them $row instead of $num ? thats the part that confuses me about php Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 28, 2010 Share Posted June 28, 2010 Change this line: <?php echo '<td><b>Song</b>: <a href="{$row['composer']}">{$row['artist']}</a> - {$row['title']}<br /><b>Dedicated By</b>:{$row['name']}<br /><b>Dedication</b>:{$row['msg']}<br /></td>' . "\n"; ?> to <?php echo "<td><b>Song</b>: <a href='{$row['composer']}'>{$row['artist']}</a> - {$row['title']}<br /><b>Dedicated By</b>:{$row['name']}<br /><b>Dedication</b>:{$row['msg']}<br /></td>\n"; ?> Ken Quote Link to comment Share on other sites More sharing options...
Vizonz Posted June 28, 2010 Author Share Posted June 28, 2010 okay new problem while ($row = mysql_fetch_assoc($results)) { results in mysql_fetch_assoc() expects parameter 1 to be resource, null given in Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 28, 2010 Share Posted June 28, 2010 Sorry "$result", not "$results" Ken Quote Link to comment Share on other sites More sharing options...
Vizonz Posted June 28, 2010 Author Share Posted June 28, 2010 okay that works now and its alot cleaner then my huge amount of code but how do i get it to display that now with numbers now its like this Song: 4 Non Blondes - What's Up Dedicated By:Amber Dedication:I love this song i want it to be 1. Song: 4 Non Blondes - What's Up Dedicated By:Amber Dedication:I love this song 2. Song: 4 Non Blondes - What's Up Dedicated By:Amber Dedication:I love this song 1. 2. 3. 4. 5. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 28, 2010 Share Posted June 28, 2010 Is there any reason why you're using a table, the result you want can be obtained using an ordered list: <?php $query = "SELECT DISTINCT requestlist.songID, requestlist.msg, requestlist.name, requestlist.status, songlist.ID, requestlist.ID, songlist.artist, songlist.title, songlist.count_requested, songlist.composer FROM radio.requestlist INNER JOIN radio.songlist ON requestlist.songID = songlist.ID WHERE requestlist.status = 'played' ORDER BY songlist.last_requested DESC LIMIT 5; "; $result=mysql_query($query); $num=mysql_num_rows($result); echo "<ol>\n"; while ($row = mysql_fetch_assoc($result)) { echo "<li><b>Song</b>: <a href='{$row['composer']}'>{$row['artist']}</a> - {$row['title']}<br /><b>Dedicated By</b>:{$row['name']}<br /><b>Dedication</b>:{$row['msg']}</li>\n"; } echo "</ol>\n"; ?> Ken Quote Link to comment Share on other sites More sharing options...
Vizonz Posted June 28, 2010 Author Share Posted June 28, 2010 lol I did not even think of that thanks ken for the help you have a great day Quote Link to comment Share on other sites More sharing options...
Vizonz Posted June 29, 2010 Author Share Posted June 29, 2010 okay i wanted to reopen my topic so i dont have to start a new one. saves on clutter. <?php $query = "SELECT DISTINCT requestlist.songID, requestlist.msg, requestlist.name, requestlist.status, songlist.ID, requestlist.ID, songlist.artist, songlist.title, songlist.count_requested, songlist.composer FROM radio.requestlist INNER JOIN radio.songlist ON requestlist.songID = songlist.ID WHERE requestlist.status = 'played' ORDER BY songlist.last_requested DESC LIMIT 5; "; $result=mysql_query($query); $num=mysql_num_rows($result); echo "<ol>\n"; while ($row = mysql_fetch_assoc($result)) { echo "<li><b>Song</b>: <a href='{$row['composer']}'>{$row['artist']}</a> - {$row['title']}<br /><b>Dedicated By</b>:{$row['name']}<br /><b>Dedication</b>:{$row['msg']}</li>\n"; } echo "</ol>\n"; ?> the above code is very usefull but now i need to do something a little different. i want to throw this code on a page. and grab the top ten song_played field for the artist id that this is ran on. and instead of it being in rows i want the results to be marquee 1. 2. 3. also need to be able to display mysql dates in day month year. and basic time 12:30 or 2:30 so on any help please i been trying to build the queries and do this stuff myself but i am just frustrating myself and this site i am doing is huge so any help is greatly and i mean greatly appreciated Quote Link to comment Share on other sites More sharing options...
Vizonz Posted June 29, 2010 Author Share Posted June 29, 2010 okay i now figured out how to marquee the results. but cant figure out the query to show only the songs by that artist. and the timestamp thing 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.