Jump to content


Photo

Retrieve database, descending order


  • Please log in to reply
6 replies to this topic

#1 Janj

Janj

    Member

  • Members
  • PipPip
  • 25 posts

Posted 27 January 2013 - 07:35 PM

Hey there, I need some help figuring out how to do something.
What I need is a way to recall the whole database in descending order by artnum (the number of each entry). artnum begins at 001 and continues 002 003 and so on. Then it echoes them like this:


<div class="big"><a href="newsn.php?art=[INSERT art_title_url HERE]">[INSERT art_title HERE]</a></div>
[INSERT art_desc HERE]<br /><br />


I already know how to fill them in, I just don't know how to make it so that I have one for each entry, so it would be like:


<div class="big"><a href="newsn.php?art=[INSERT 002 art_title_url HERE]">[INSERT 002 art_title HERE]</a></div>
[INSERT 002 art_desc HERE]<br /><br />

<div class="big"><a href="newsn.php?art=[INSERT 001 art_title_url HERE]">[INSERT 001 art_title HERE]</a></div>
[INSERT 001 art_desc HERE]<br /><br />


(the 001 and 002 are the artnum numbers)


This is what I have so far, but I think I'm wrong:

$result = mysql_query("SELECT * FROM articles ORDER BY artnum DESC");

while($row = mysql_fetch_array($result))
{
$art_title=$row['art_title'];
$art_title_url=$row['art_title_url'];
$art_desc=$row['art_desc'];
}

The main thing about that code is I need a way to echo every piece of information.

I'm sorry if you don't understand, it's sort of hard to explain. If you want, post here and I'll try to say it to where you'll understand. My MySQL version is 5.0.91-log

#2 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,381 posts
  • LocationCheshire, UK

Posted 27 January 2013 - 07:43 PM

echo is useful in such stuations

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#3 Janj

Janj

    Member

  • Members
  • PipPip
  • 25 posts

Posted 27 January 2013 - 07:45 PM

I understand how to use echo, but what do I put in there? The whole MySQL statement? Sorry, I'm genuinely confused about this.

#4 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 27 January 2013 - 07:50 PM

You echo what you want echoed.... What did you try?
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#5 Janj

Janj

    Member

  • Members
  • PipPip
  • 25 posts

Posted 27 January 2013 - 07:52 PM

Well, I haven't tried anything, because I don't understand :/
I need to echo every single row. Is there an all-inclusive? Or do I echo this? $result = mysql_query("SELECT * FROM articles ORDER BY artnum DESC");

Edited by Janj, 27 January 2013 - 07:53 PM.


#6 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,381 posts
  • LocationCheshire, UK

Posted 27 January 2013 - 07:56 PM

like this

while($row = mysql_fetch_array($result))
{
$art_title=$row['art_title'];
$art_title_url=$row['art_title_url'];
$art_desc=$row['art_desc'];

echo "<div class=\"big\"><a href=\"newsn.php?art=$art_title_url\">$art_title</a></div>
$art_desc<br /><br />";
}

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#7 Janj

Janj

    Member

  • Members
  • PipPip
  • 25 posts

Posted 27 January 2013 - 08:00 PM

like this

while($row = mysql_fetch_array($result))
{
$art_title=$row['art_title'];
$art_title_url=$row['art_title_url'];
$art_desc=$row['art_desc'];

echo "<div class=\"big\"><a href=\"newsn.php?art=$art_title_url\">$art_title</a></div>
$art_desc<br /><br />";
}


Thanks so much! I have it working now!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com