Topic awaiting preservation: MySQL Help please (Page 1 of 1) |
|
---|---|
Paranoid (IV) Inmate From: beyond the gray sky |
posted 07-29-2012 17:14
Hi all! I'm working on a project to make my life easier at my job. I've recently been given the task of managing work that comes in from other offices and after seeing the way this has been done in the past, I've decided to make a database app to store all of this information. I've got my tables set up and forms to input new data and others to view the data, but it's been a long time since I've done any coding and I'm having some trouble getting a couple things figured out. code: mysql_select_db("hhc", $connection); $SQL = mysql_query("SELECT * FROM studies WHERE lname LIKE '$lname%' AND fname LIKE '$fname%' ORDER BY lname"); echo "<table><tr><th>First Name</th><th>Last Name</th><th>Date of Birth</th> <th>Ordering</th><th>Reading</th><th>Date of Service</th><th>Actions</th></tr>\n"; while($row = mysql_fetch_array($SQL)) { ?> <tr> <td><? echo $row['fname'] ?></td> <td><? echo $row['lname'] ?></td> <td><? echo $row['ptdob'] ?></td> <td><? echo $row['ordering'] ?></td> <td><? echo $row['reading'] ?></td> <td><? echo $row['dos'] ?></td> <td> <a href="edit.php?uid=<? echo $row['uid'] ?>"><img src="img/edit.png"></a> <a href="delete.php?uid=<? echo $row['uid'] ?>"><img src="img/delete.png"></a> </td> </tr> <? } mysql_close($connection); echo "</table>\n";
|
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 07-30-2012 09:16
You probably need to look into SQL joins - which do just what they say, they 'join' tables together. code: SELECT studies.*, hhcmds.* FROM studies, hhcmd WHERE hhcmd.doc_id = studies.refering_doctor AND studies.lname LIKE '$lname%' AND studies.fname LIKE '$fname%' ORDER BY studies.lname
|
Paranoid (IV) Inmate From: beyond the gray sky |
posted 08-02-2012 02:12
thanks for the reply, TP. the statement you gave me pulls the right records, but I can't seem to get the data to show up right. code: $SQL = mysql_query(" SELECT studies.*, hhcmds.* FROM studies, hhcmds WHERE hhcmds.uid = studies.reading AND studies.lname LIKE '$lname%' AND studies.fname LIKE '$fname%' ORDER BY studies.lname "); echo "<table><tr><th>First Name</th><th>Last Name</th><th>Date of Birth</th><th>Ordering</th><th>Reading</th><th>Date of Service</th><th>Actions</th></tr>\n"; while($row = mysql_fetch_array($SQL)) { ?> <tr> <td><? echo $row['studies.fname'] ?></td> <td><? echo $row['studies.lname'] ?></td> <td><? echo $row['ptdob'] ?></td> <td><? echo $row['ordering'] ?></td> <td><? echo $row['hhcmds.lname'] ?></td> <td><? echo $row['dos'] ?></td> <td> <a href="edit.php?uid=<? echo $row['uid'] ?>"><img src="img/edit.png"></a> <a href="delete.php?uid=<? echo $row['uid'] ?>"><img src="img/delete.png"></a> </td> </tr> <? }
|
Paranoid (IV) Inmate From: beyond the gray sky |
posted 08-02-2012 03:06
well... after a little more searching, I answered my own question. but for the sake of anyone who might be searching and come across this, here's what I came up with. code: $SQL = mysql_query(" SELECT s.uid AS s_uid, s.fname AS s_fname, s.lname AS s_lname, s.ptdob AS s_ptdob, r.lname AS r_lname, h.lname AS h_lname, s.dos AS s_dos FROM studies s LEFT JOIN refmds r ON r.uid = s.ordering LEFT JOIN hhcmds h ON h.uid = s.reading WHERE s.lname LIKE '$lname%' AND s.fname LIKE '$fname%' "); echo "<table><tr><th>First Name</th><th>Last Name</th><th>Date of Birth</th><th>Ordering</th><th>Reading</th><th>Date of Service</th><th>Actions</th></tr>\n"; while($row = mysql_fetch_array($SQL)) { ?> <tr> <td><? echo $row['s_fname'] ?></td> <td><? echo $row['s_lname'] ?></td> <td><? echo $row['s_ptdob'] ?></td> <td><? echo $row['r_lname'] ?></td> <td><? echo $row['h_lname'] ?></td> <td><? echo $row['s_dos'] ?></td> <td> <a href="edit.php?uid=<? echo $row['s_uid'] ?>"><img src="img/edit.png"></a> <a href="delete.php?uid=<? echo $row['s_uid'] ?>"><img src="img/delete.png"></a> </td> </tr> <? } mysql_close($connection); echo "</table>\n"; ?>
|
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 08-02-2012 14:45
Seems you're getting along really well |
Paranoid (IV) Inmate From: beyond the gray sky |
posted 08-04-2012 14:12
Thanks. those aliases took a minute for me to wrap my head around, but I think I've got it figured out. I took a couple of ancient database programming classes years ago, so I know a little about the concepts - it's just the syntax and best practices that I have to figure out lol |