This is a read-only archive. No new posts or registrations. Privacy Page
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.

Looking for the outcome? Ask AI

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.

Ask AI

AI can make mistakes. Check the cited posts. Archived advice can be out-of-date

Don't include personal information. Questions and selected public posts go to OpenAI. About Ask AI