Jump to content

Recommended Posts

to be clear, I have to tables. one called userinfo, and one is called usercus, however, I can only do one select query, like below:

SELECT * FROM userinfo $where
$where is not important, its just a mess of different query factors of a customize search, but my real problem is about my other table, usercus, it has a column called photo, however, this search requires the information of that column, how can I do one query that involves the information of that table?
Thanks
Ted
Link to comment
https://forums.phpfreaks.com/topic/33720-mysql-search-again-but-different/
Share on other sites

Yes, the username is a good example, so your query would look something like this...

[code]<?php
$sql = "SELECT i.*, p.photo FROM userinfo i, usercus p WHERE i.username = p.username AND i.username LIKE '%$user%' AND i.gender = '$gender'";
?>
[/code]

This is assuming that your username column is related in both tables and that your photo column is in the usercus table and the gender column is in the userinfo table.

Regards
Huggie
Ted, if you don't know what fields are called then always print the contents of the array out...

[code]<?php
// Set the code and query the database
$sql = "SELECT i.*, p.photo FROM userinfo i, usercus p WHERE i.username = p.username AND i.username LIKE '%$user%' AND i.gender = '$gender'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);

// Echo the array to see what the columns are called...
echo "<pre>\n";
print_r($row);
echo "</pre>\n";
?>[/code]

Regards
Huggie
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.