Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 20th, 2005, 05:20 AM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to elania
Default how to display the result

i'm doing VIEW function. and this is my Mysql statement:

$sql = "SELECT * FROM staff, student WHERE f_Username.staff LIKE '$user' OR t_Username.student LIKE '$user'";
$result = mysql_query($sql, $conn);

the result can be from table staff or student. now how am i suppose to display the result?

i'm am total newbie
__________________
i\'m am total newbie
Reply With Quote
  #2 (permalink)  
Old February 20th, 2005, 12:23 PM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i think you got your query the other way around. It should be like:

$sql = "SELECT * FROM staff, student WHERE staff.f_Username LIKE '%$user%' OR student.t_Username LIKE '%$user%'";
$result = mysql_query($sql) or die (mysql_error());

while ($row = mysql_fetch_assoc($result)){
    //Here you can print your data however you like.
    //$row is an array that contains all of your results and you can
    //display them like the following.
    echo $row['f_Username'];
}

----------------
Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq
Reply With Quote
  #3 (permalink)  
Old February 21st, 2005, 11:57 AM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to elania
Default

echo $row['f_Username']; -- will this display result from table student?

i'm am total newbie
Reply With Quote
  #4 (permalink)  
Old February 21st, 2005, 03:07 PM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

if the fieldname is not unique between the two tables, you might have some problems. So to obviate this problem, either use the numerical index of the array or do this as your select statement.:

$sql = "SELECT f_Username as username, t_Username as staff_username FROM staff, student WHERE staff.staff_username LIKE '%$user%' OR student.username LIKE '%$user%'";


----------------
Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Decode function to display result in same row yogeshyl SQL Language 0 July 2nd, 2008 12:40 AM
Display Search Engine result in table using JSP sbc789 JSP Basics 3 December 3rd, 2007 11:35 PM
GridView and SQL More than one result = one result DarkForce ASP.NET 2.0 Basics 0 July 20th, 2007 04:29 AM
How to display the result in sqlpus editor lily611 Oracle 3 November 22nd, 2006 03:26 PM
display the result of query in textbox. Abhinav_jain_mca ADO.NET 4 August 3rd, 2004 03:34 AM



All times are GMT -4. The time now is 07:52 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.