Jump to content

Archived

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

sw0o0sh

problem ascending information from mysql

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.

Share this post


Link to post
Share on other sites
I want the mysql query to list my topic names by order of ID number on a php page.

Share this post


Link to post
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..

Share this post


Link to post
Share on other sites
[code]
<?php

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

$result = mysql_query($query);

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

   $record['name'];

}
?>
[/code]

Share this post


Link to post
Share on other sites
Fatal error: Call to undefined function: () in E:\Internet Information Services\Webs\FTP\com.davessonicsite.www\chaoworld\main.php on line 19

Share this post


Link to post
Share on other sites
[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..

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites

×

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.