Jump to content

problem ascending information from mysql


sw0o0sh

Recommended Posts

Hi, Im working on a miniature forum using my own stupid techniques, and I have a table called "chaoworld_chat". To make this simple, I have two rows im going to share, one called id, and the other topic .

Ive been messing around with code to try and LIST the topic names while its being ordered with the ID number.

[code]
$result = mysql_query("SELECT * FROM chaoworld_chat ORDER BY id");
while($r=mysql_fetch_array($result))
{
   $name=$r["topic"];
   
   echo "$name<br>";
}
[/code]

I know I'm doing something wrong here.. can anyone help me fix my error..

Pretend theres 3 topics,

topic name : hi ; Id = 3
topic name: hello; Id = 1
topic name: bye; id = 2

I need this code fixed so it gives me ..

hello
bye
hi

On a page when called from the mysql table.. thanks.
Link to comment
https://forums.phpfreaks.com/topic/16409-problem-ascending-information-from-mysql/
Share on other sites

[quote author=redarrow link=topic=102819.msg408629#msg408629 date=1154579427]
Does this help.
<?php

$query="SELECT * FROM chaoworld_chat ORDER BY id DESC";

$result = mysql_query($query);

while( list($key,$val)=each($result) ) {

   echo"$key;$val";

}

?>

ps what error?
[/quote]



Warning: Variable passed to each() is not an array or object in E:\Internet Information Services\Webs\FTP\com.davessonicsite.www\chaoworld\main.php on line 15


No it does help. All I want to do is list the topic name in order by the id on a php page in an array..
[img]http://img486.imageshack.us/img486/268/databasehx7.png[/img]

[code]
<?

if (!$link = mysql_connect('localhost', 'davessonicsite', 'mmhmm')) {
  echo 'Could not connect to mysql';
  exit;
}

if (!mysql_select_db('davessonicsite', $link)) {
  echo 'Could not select database';
  exit;
}


$query="SELECT * FROM chaoworld_chat ORDER BY id DESC";

$result = mysql_query($query);

while($record_fetch_assoc($result)){

  $record['topic'];

}
?>[/code]



.. all i want is the topic names displayed on a PHP page ordered by the id numbers..
[code]
<?php

$db = mysql_connect("localhost" , "davessonicsite", "mmhmm");
mysql_select_db("databasename",$db)OR DIE("Error database problam");

$query="SELECT * FROM chaoworld_chat ORDER BY id DESC";

$result = mysql_query($query);

while($record=mysql_fetch_assoc($result)){

echo"<br>$record['id'] : $record['topic']  : $record['message']<br>";
}
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.