Jump to content

Build Theme!
  •  
  • Infected?

WE'RE SURE THAT YOU'LL LOVE US!

Hey there! :wub: Looks like you're enjoying the discussion, but you're not signed up for an account. When you create an account, we remember exactly what you've read, so you always come right back where you left off. You also get notifications, here and via email, whenever new posts are made. You can like posts to share the love. :D Join 91867 other members! Anybody can ask, anybody can answer. Consistently helpful members may be invited to become staff. Here's how it works. Virus cleanup? Start here -> Malware Removal Forum.

Try What the Tech -- It's free!


Photo

PHP: Get MYSQL Entry


  • Please log in to reply
1 reply to this topic

#1 gerrydevis

gerrydevis

    New Member

  • Banned
  • Pip
  • 3 posts

Posted 09 January 2010 - 06:54 AM

Okay. I've been learning PHP for some time, but this will be one of my first real attempts to create something with it. I've kind of got an idea of what I'm doing, but I need to know how to grab database entries by specifying the value of one of the fields. E.g.. ID - Name - Species 1 - Mark - Human 2 - Zulu - Alien 3 - Rooly - Alien 4 - Billy - Human How can I grab all database entries with the Species value of "Alien"? I'll be then trying to display them like this: CODE echo "ID: {$row['id']} - " . "Name: {$row['name']} - " . "Species: {$row['species']}<br>"; And repeating it to create a table listing Alien characters

    Advertisements

Register to Remove


#2 jpshortstuff

jpshortstuff

    Teacher Emeritus

  • Authentic Member
  • PipPipPipPipPipPip
  • 5,710 posts

Posted 09 January 2010 - 07:48 PM

Have you tried something along the lines of this?
$result = mysql_query("SELECT * FROM MyTable WHERE Species='Alien'");

//validate $result...

while ($row = mysql_fetch_assoc($result)) {
	echo "ID: {$row['id']} - " .
		 "Name: {$row['name']} - " .
		 "Species: {$row['species']}<br>";
}

mysql_free_result($result);
Assuming you have already established the DB connection, and "MyTable" is the name of your table.

I haven't done PHP+MYSQL for a long time, but that's the gist of general db queries if I remember rightly. Take your time to teach yourself MYSQL - a clever MYSQL query can save you a lot of time/php code.

Hope that helps.

Proud Graduate of the TC/WTT Classroom

At weekends (GMT) I may not be able to reply promptly due to various commitments. Please be patient and I will respond as soon as I can.

My help is free, however, if you wish to make a small donation to show appreciation and to help me continue the fight against Malware, then click here Posted Image

Need help remembering those important computer maintenance tasks? Let SCars do it for you.

Posted Image

Related Topics



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users