Generating Simple List from Results in DB
Moderator: General Moderators
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
Generating Simple List from Results in DB
Hello,
I have sucessfully created a simple voting system with PHP / MYSQL thanks to the help of a couple of people on this forum..
However, I have one more question, I was wondering if somebody could give me a tutorial or somthing on how to do this.
I am trying to make a list generated by PHP / MYSQL that shows the number of votes for each of the things I have voted.. But I want it set up a specific way that if the # of votes are the same for two or however many things they are at the same order number.
For Ex.
Bob was voted 0 times.
Billy was voted 3 times.
Mike was voted 5 times.
Paul was voted 2 times.
Joe was voted 0 times.
John was voted 5 times.
Scott was voted 1 time.
Barry was voted 2 times.
Phil was voted 0 times.
The list that would be generated is
1. John
1. Mike
2. Billy
3. Paul
3. Barry
4. Scott
5. Joe
5. Phil
5. Bob
Do you understand what I mean?
Thanks Alot!!!!!!
Any help would be greaT!!!
I have sucessfully created a simple voting system with PHP / MYSQL thanks to the help of a couple of people on this forum..
However, I have one more question, I was wondering if somebody could give me a tutorial or somthing on how to do this.
I am trying to make a list generated by PHP / MYSQL that shows the number of votes for each of the things I have voted.. But I want it set up a specific way that if the # of votes are the same for two or however many things they are at the same order number.
For Ex.
Bob was voted 0 times.
Billy was voted 3 times.
Mike was voted 5 times.
Paul was voted 2 times.
Joe was voted 0 times.
John was voted 5 times.
Scott was voted 1 time.
Barry was voted 2 times.
Phil was voted 0 times.
The list that would be generated is
1. John
1. Mike
2. Billy
3. Paul
3. Barry
4. Scott
5. Joe
5. Phil
5. Bob
Do you understand what I mean?
Thanks Alot!!!!!!
Any help would be greaT!!!
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
Thanks for the tip Feyd...
I checked it out and created a script, I thought would work...
But... I got a little problem with it.
The Code:
Outputs:
THANKS ALOT

I checked it out and created a script, I thought would work...
But... I got a little problem with it.
The Code:
Code: Select all
<?
$username2= "muot_report";
$password2= "apssswrod";
$database2= "muot_report";
$connection2 = mysql_connect('localhost',$username2,$password2);
mysql_select_db($database2);
$sql4 = "SELECT * FROM `report` WHERE moty =1 ORDER BY `votes` DESC";
$result = mysql_query($sql4) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
echo '<tr><td align=center>$row["prevname"]</td><td align=center>$row["votes"]</td></tr>';
}
?>Any idea why it isnt putting in the correct info.. It outputs the correct number of rows...NAME # OF VOTES
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
$row["prevname"] $row["votes"]
THANKS ALOT
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
single quotes will parse the strings as is, double quotes will parse the variables.
Or simply escape your single quotes
Code: Select all
$foobar = 'Hello World';
echo '$foobar';
//prints $foobar
echo "$foobar";
//prints Hello WorldCode: Select all
echo 'Lets escape '. $foobar .' so it will parse';
//prints Lets escape Hello World so it will parse- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
.... because you will end up with something likenickman013 wrote:Oh, But when I reverse them.. I get... a parse error
The error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/muot/public_html/moty_standings.php on line 12
Code: Select all
echo "<tr><td align=center>$row["prevname"]</td><td align=center>$row["votes"]</td></tr>";- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Haven't we gone over this with you before?
read http://php.net/language.types.string for how to make strings.
read http://php.net/language.types.string for how to make strings.
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York