MySQL Forums
Forum List  »  Newbie

I can't figure this out...wildcards
Posted by: Johnie Karr
Date: March 26, 2005 08:52PM

Hi everybody,

I'm new to this forum, and new to MySql...well, actually, I've been using MySql for about 5 hours or so now. I'm using a tutorial to learn the basics and get me started, but I'm running into a problem with wildcards.

The code below creates a table, but displays no results. There should be 2 results displayed. One for age 21 and one for age 23, if I change WHERE age='2%' to WHERE age='21' then it works with no problem, but the wildcard should dispay both ages. I can't figure out what is wrong since I'm not getting any error messages.

Can someone tell me what's wrong with the code?

Note: for obvious reasons, I changed the username and password to <user> and <pass> respectivley.

<?php
// Make a MySQL Connection
mysql_connect("localhost", "<user>", "<pass>") or die(mysql_error());
mysql_select_db("godsbibl_test") or die(mysql_error());

// Get a specific result from the "example" table
$result = mysql_query("SELECT * FROM example
WHERE age='2%'") or die(mysql_error());

echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Age</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['name'];
echo "</td><td>";
echo $row['age'];
echo "</td></tr>";
}
echo "</table>";



?>

Thanks,
Johnie Karr
Church of Christ
www.godsbible.org

Options: ReplyQuote


Subject
Written By
Posted
I can't figure this out...wildcards
March 26, 2005 08:52PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.