Solved

Still Stuck on the easy stuff...

Posted on 2000-03-13
8
208 Views
Last Modified: 2008-03-06
The more I try, the more confused I get...

I have a table called "member" in MySQL.
The columns within member are:
"ID"; "name"; "email"; "status"

Suppose the value of ID was entered from an HTML form, how could I say:

"If the HTML form entry = the ID in table 'member', output the details from that row.
else loop the above phrase until the bottom of table member is reached or until a match is found"?

*I wasn't born to program!*

Cheers (again)... and double the points this time - woohoo.

Dave
0
Comment
Question by:dht1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 2

Expert Comment

by:gravity
ID: 2614244
OK then, this should work with a bit of luck...
$database  is the name of your database which contains the member table.
$id is the id as given by the HTML form.
<?
      $database = "databasename";
      $conn = mysql_connect("localhost","root","");
      $db = mysql_select_db($database,$conn);

      $sql = "select name,email,status from member where ID='$id'";
      $query = mysql_query($sql);
      echo "<TABLE>\n";
      echo "<TR><TD>Name</TD><TD>Email</TD><TD>Status</TD></TR>\n";
      while ($row=mysql_fetch_row($query)) {
            echo "<TR><TD>$row[0]</TD><TD>$row[1]</TD><TD>$row[2]</TD></TR>\n";                  
      }
      echo "</TABLE>";
?>

What happens here is quite simple... you query the SQL (in $sql) in MySQL and then get PHP to fetch one row at a time of said query.
The fields of each row are returned in an array, in this case $row.
0
 
LVL 2

Expert Comment

by:gravity
ID: 2614250
D'oh !!!
The line above which reads :

"$query = mysql_query($sql);"

Should in fact read :

"$query = mysql_query($sql,$db);"
0
 

Author Comment

by:dht1
ID: 2614605
Thanks, Gravity - your answer certainly answered my question...

Stupidly however, I neglected to mention that I wanted to use the result in order to use an if command...

ie. If a match is found, then do x.

How would I insert a boolean variable to state that a match had been made?

Presumably I could then insert a statement to the effect of:

if (x = "true"): do x, y or z

?

I appreciate that I am a complete plonker... but if you can incorporate this additional point, I'll increase the points (assuming you care about the points!)

Thanks (and sorry),

Dave
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
mafweb earned 100 total points
ID: 2615143
Hi Dave,

how about this:

//connect to the db

mysql_query("select * from members where ID=$id);
if (mysql_affected_rows()>0)
      //you got a matching id and now,
      //you can go through the entries with
      //mysql_fetch_row()
else
      //output form again

with this, you will get at once all of the entries of members with matching IDs (or none, if no matching IDs exist).

hope this helps

maf
0
 

Author Comment

by:dht1
ID: 2615366
EXCELLENT!

I'm slowly getting there!

Gravity, if you particularly want some points, let me know.

Thanks,

Dave
0
 
LVL 2

Expert Comment

by:gravity
ID: 2615547
It would be appreciated :)
0
 

Author Comment

by:dht1
ID: 2615555
I'll post another question for you to answer - sorry, I don't know if there's a tidier method.
0
 
LVL 2

Expert Comment

by:gravity
ID: 2617342
Groovyness - unfortunatly, I don't think there's another way of doing it, such is life...

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question