Jump to content

Numbered list and first record loses format


Vizonz

Recommended Posts

$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.

 

Link to comment
Share on other sites

okay i have to actually post the code that was just a edited version :P

 

$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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :P

 

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

okay that works now :)  and its alot cleaner then my huge amount of code :P

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.