This is a read-only archive. No new posts or registrations. Privacy Page Still need help? Ask the volunteers at Geeks to Go, free.
Software

PHP: Get MYSQL Entry

1 min read

This thread's last reply is from . Advice, software, and links below may be out of date — treat specific steps and download links with caution.

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']}
"; And repeating it to create a table listing Alien characters
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']}
"; } 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.

Still having this problem?

This topic is from the What the Tech archive and can't take new replies. Geeks to Go is an active, free help community run by volunteers. Post your question there and a person, not a bot, will work through it with you.

Ask on Geeks to Go →