Jump to content


Photo

problem ascending information from mysql


  • Please log in to reply
9 replies to this topic

#1 sw0o0sh

sw0o0sh
  • Members
  • PipPipPip
  • Advanced Member
  • 151 posts
  • LocationMassachusetts

Posted 03 August 2006 - 04:20 AM

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.

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

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.

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 03 August 2006 - 04:24 AM

any error messages? not showing expected results? can you be more specific?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 sw0o0sh

sw0o0sh
  • Members
  • PipPipPip
  • Advanced Member
  • 151 posts
  • LocationMassachusetts

Posted 03 August 2006 - 04:25 AM

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

#4 sw0o0sh

sw0o0sh
  • Members
  • PipPipPip
  • Advanced Member
  • 151 posts
  • LocationMassachusetts

Posted 03 August 2006 - 04:34 AM

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?




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

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 03 August 2006 - 04:38 AM

<?php

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

$result = mysql_query($query);

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

   $record['name'];

 }
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 sw0o0sh

sw0o0sh
  • Members
  • PipPipPip
  • Advanced Member
  • 151 posts
  • LocationMassachusetts

Posted 03 August 2006 - 04:39 AM

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

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 03 August 2006 - 04:42 AM

add the database post your code please cheers
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 sw0o0sh

sw0o0sh
  • Members
  • PipPipPip
  • Advanced Member
  • 151 posts
  • LocationMassachusetts

Posted 03 August 2006 - 04:46 AM

Posted Image

<?

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'];

 }
?>



.. all i want is the topic names displayed on a PHP page ordered by the id numbers..

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 03 August 2006 - 04:53 AM

<?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>";
}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 03 August 2006 - 04:57 AM

what's your current output?
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users