Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





MySQL: Searching With Joins Or Delimited List


I'm trying to implement a solution where a given company can set a list of the coutries in which it has branches.

My first thought is this:

'company' (id, co_name)
'location' (id, co_id, loc_code)

And when the customer want to know if a company has a location in Belize:

select c.co_name from company c left outer join location l on l.co_id = c.id where l.loc_code = 'BZ'

My second thought is adding loc_code to company: Code:




View Complete Forum Thread with Replies

Related Forum Messages:
Simple A-Z Link List For Searching Mysql Database
I'm trying to set-up a simple A-Z list so that people can search a mysql database by each letter. Click on "A" get all records in the DB that start with "A". I have it working no problem but i want to be able to add "#" so that the user can get all records that start with a Number.

For some reason the query i'm running won't grab any records that start with a number?

here is the query:

View Replies !
Easy Comma-delimited List To Dropdown Box Converter
I was working on a simple converter when I realized that by not setting the id param of the option tag, it wasn't going to send the value of the dropdown box to my php script. I had this to start with: Code:

View Replies !
Regular Expression :: Find Word Matches To Words In A Comma-delimited List
What's the *right* way to find word matches to words in a comma-delimited list. For example, if I have the following comma-delimited list of categories in a mysql db field:

gameboy, nintendo, playstation

and I do a search, I know I can use regexp to do something like:

select * from categories where regexp 'gameboy,'

Notice that I have the comma in there to match the whole word and the comma without matching part of a word (to prevent unwanted matches such as "play" to "playstation" or "game" to "gameboy"). The problem I'm running into is words that match that match the end of each word next to the comma (in this example, "boy" and "station"). What's the right way to match a word *exactly* using regexp *without* also matching *part* of a word.

View Replies !
Mysql Joins
I have created two tables. In one I keep user informations like:

User_id,
User_name,
User_email,
User_IP.

In second table I keep message information like:

email_id
email_text
email_sender_id
email_receiver_id
email_date_id
email_title

I want to join these so that it shows like these result:
email title --- email date --- email from --- email to --- email text

View Replies !
MySQL Inner Joins
Working on my final project for a PHP college course. I am working on a shopping cart at this point. I am hacking the script which came with my text book to make it work with my db. Code:

View Replies !
Using JOINs In MySQL Query
I have a set of database tables. three contain user info, event info and fee info one table contains the id's linking user to event one table links fee's to events one table links users to fees:

I'm thinking this might be a little too complicated and maybe I should just have a fee field in the events table although not all fees are associated with an event and not all events have fees. In fact less then 5% of the events have fees. So the way I have it is probably best. Code:

View Replies !
Searching Dynamic Driven List
I have a members database will all their personal details in. I have a page running a SQL query to display a complete list of all these people. This is what my query looks like:

$sql_prop = "SELECT * FROM $db.members WHERE area = '".$_REQUEST['area']. "' ORDER BY name ASC;
$result_prop = mysql_query($sql_prop) or die(error_report("Mysql Error", mysql_error()."

$sql_prop", $_SERVER['REMOTE_ADDR']));

"Error Report" is just one of my functions. I have two forms fields on this page, "Name" and "Address". I want to be able to search the listing that this SQL query has returned for those fields, ie. the user enters "John" in the form field and it returns all entries within the query matching "John". The reason I'm using this:

area = '".$_REQUEST['area']. "'
in the WHERE clause, is just to ensure that the person viewing this list can only see members that are in his area. On the previous page there is a piece of code that gets the session "area" and brings it across to this page. I'm keen on keeping that code in. It works for me at the moment.

Any ideas? How can I search this already filtered list?

View Replies !
Mysql Joins Returning Null
I dont know how to explain it so ill show you the code

$select=$q("SELECT UserExp.CrimeExp, User.Nerve,  CrimeList.ExpNeeded, CrimeList.ExpGain, CrimeList.ExpLoss, CrimeType.Nerve FROM UserExp,User,CrimeList,CrimeType
where CrimeList.CrimeID=CrimeType.ID AND CrimeType.ID='$_GET[type]'")or die(mysql_error());
$select=mysql_fetch_array($select);
$Test=$select[User.Nerve];
$Test2=$select[CrimeType.Nerve];
echo("Test: $Test Test2: $Test2 ");
if($select[User.Nerve]<$select[CrimeType.Nerve]){
Basicly there both returning null, any advice in getting around this problem

View Replies !
Reading Excel To MySql Or Comma Delimited ...
right direction on how to deal with an xls
flie.

but the only other file I have to work
with is pdf.

I'm not sure, is xls the better of two evils?


View Replies !
Importing A Flat Pipe Delimited File Into A MySQL Data Table
I have done this in perl but eeew I don't want to use perl anymore. I
want to be able to take a flat file that looks like this:

mbriones@...|Marian|Briones
bobsmith@...|Bob|Smith
janedoe@...|Jane|Doe
(etc)

The table has more than 3 fields, so I'd want to process the flat file
and then do an INSERT into mailinglist SET field=$value for each line.

Does someone have a nice way for me to do this? The flat file will be
uploaded to the server via a form (copy) and then be processed.

View Replies !
Searching In Mysql
Say in my database I've got a table with structure of

time, long, lat

Time is in the timestamp. I want to write some code that allows the user to input in two times, A and B. And the program will output all the data from time A to time B.

The thing is, I can't just get the user to enter the date right? since the database will search for an exact time, down to the seconds..

The only way I can think of getting round this is to read all the times, and put them into two drop down lists and the user just choose the from and the end time. Though I don't know how to do this and will have to google stuff..

Any other suggestions?

View Replies !
MySQL Searching
If you have a MySQL table and you only know two of the values for one row (say "Username" and "Password") how can you make a PHP script to tell you the third value on that row (like ID).

View Replies !
Searching Mysql
I just dont understand how i can take: PHP Code:

$lastmonth = mktime(0, 0, 0, date("m"), date("d")-3,  date("Y"));

and turn it into #threedaysago PHP Code:

$threedaysago = 20051128224433;
//if the current time were this.
$currenttime = 20051201224433;
// $currenttime is how my dates are stored in mysql.

View Replies !
Searching MySQL DB
Here are 4 entries in a database all under the column "name":

Shock
Barbed Shocker
Shockwave
Sudden Shock

I were to have a textbox to set search stipulations, what would my query string look like to get all of these entries to show up if I simply typed "Shock" in the textbox?  Basically, how do I get PHP/mySQl to search for something in a field, even if it isn't exact, but just contains those letters somewhere? Also, how would I make it limited to matching exactly how it is typed in the textbox (just the letters, not case-sensitive).  So if "Shock" is typed in the textbox, only the "Shock" entry would be returned.

View Replies !
MySQL Searching Not Using LIKE
I have a search function on a mysql table. The LIKE operator is letting me down though. For example, if someone puts in Blue Jacket into the search box they will get the row containing Blue Jacket in the results.

However, I ALSO want them to get the same result (possibly more) if they wrote Jacket Blue or Blue or Jacket. I know this is possible but it is way too complicated for me. Here is the line from my code:

$query = "select a.itemname,a.shortdescription,a.longdescription2,a.longdescription1,a.image1_small,a.price,a.productid,a.category from products a,category b where a.itemname like '%$searchtext%' or a.shortdescription like '%$searchtext%' or a.longdescription2 like '%$searchtext%' or a.longdescription1 like '%$searchtext%' and a.category = b.catid group by a.productid order by a.price,a.itemname";

View Replies !
Searching Several Columns In MYSQL
I wonder if anyone can point me in the right direction on this, I am trying to search multiple columns on a single database and display the info.

I have this set up but it only queries one.

$query_rsSearch = sprintf("SELECT * FROM database WHERE column1 LIKE '%%%s%%'", $colname_rsSearch);

The above works fine for one column but I am having difficulty making it search more than one, I have been trying this method.

$query_rsSearch = sprintf("SELECT * FROM database WHERE column1,column2 LIKE '%%%s%%'", $colname_rsSearch);

But continually get error messages?

View Replies !
Searching A Table In Mysql
I've searched through these forums about searching and didnt really find anything. All the questions that were asked were unanswered. I searched google and came up with this: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

except I am not sure if thats what I should be using nor do I understand how to write a query using that. Ill just be searching 1 field in 1 table. Can somone help me with an example query string ? Also I set the field as TEXT since I will just be adding keywords separated by commas into them. Should it be something else?

View Replies !
Loose Mysql Searching
i want to figure out how to search my database loosely so if someone misspells a part of a name they are searching for it will still find similar results. kinda like how when you misspell something on Google and it says "Did you mean ? how would i go about doing this?

View Replies !
Searching MySQL DB Contents
I'm implementing a simple internal search for a site that will select articles containing specified words from a database. However, I am finding LIKE to be somewhat limiting. eg. SELECT title FROM articles WHERE content LIKE '%test%' - this returns all articles containing words test, testing, testosterone etc. Not what is required. eg.

SELECT title FROM articles WHERE content LIKE '% test %'
- this returns only articles containing the word test.

However, the latter will not pick up on the word 'test' at the very start or very beginning of the field, or when immediately prefixed or suffixed by some punctuation.

I've found that using SELECT ..blah .. LIKE '%[^a-z]test[^a-z]%'

should overcome the problem of having punctuation on either side of the search term. 've had no success with this however, and it still doesn't get around the problem of the word occuring at the start or end of a field. Does anyone have any suggestions or experience in searching for words in a DB in such a way?

View Replies !
Searching For PHP/MySQL Tutorials
If anyone knows of a site or book that would help me reach my goal of writing my own CMS, information on these would be much appreciated. As of right now though, I'm pretty new to php altogether. I can manage a little bit on my own, and I'm used to coding (thanks to two years in java courses), so it shouldn't be too hard for me to understand.

View Replies !
Searching MySql Table Using 2+ WHERE's
I want to search a big mysql table with a query something like this. However I dunno if 'WHERE a=1, WHERE b=2' would work, so I'm asking if it will and if it doesn't is there another query that would return what I'm looking for? Query:

SELECT * FROM mytable WHERE row=1, WHERE row=3 LIKE '%my_seach_string%'

View Replies !
Searching Mysql Database
Database name = files
table name = applications

In the table I have the following

ID
appname
descr

I want the people to beable to put an app name in and have the vaules show up in a table.

Or if someone could show me a link to a site that shows you how to do this that would be cool too.

View Replies !
Mysql -> Searching Age Between Two Numbers
how to search mysql for results between two ages? this question isn't clear? ok, check out this sql. Code:

View Replies !
And MySQL - Searching A Database
i am having problems while searching for members on my website.. i have a form that users fill in before being able to click on a 'search' button.. Code:

View Replies !
Searching For Multiple Words In Mysql
I've got a table containing three columns:

Region (these are 8 predetermined values)
Club Name (an open text field which always contains more than one word)
url (contains a url)

On my search page I have two fields that can be used. The first is a drop down box with the regions in, and the other is an open text field searching the clubname field.

I would like to be able to search the table by either:

1. selecting the region on it's own (this works at the moment!!)
2. selecting a region and either one or more keywords (this works if the keyword is the first word in the clubname field in the database)
3. leaving the region blank (on the null value) and entering one or more keywords;

This is the current code:

<?php
mysql_connect (localhost, username, password);
mysql_select_db (swimclub_db);
if ($region == "")
{$region = '%'}
if ($club_name == "")
{$club_name = '%'}
$result = mysql_query ("SELECT * FROM clubs
WHERE region LIKE '$region%'
AND club_name LIKE '$club_name%'
");

if ($row = mysql_fetch_array($result)) {
do {
print $row["region"];
print (" ");
print $row["club_name"];
print (" ");
print $row["url"];
print ("<p>");
} while($row = mysql_fetch_array($result));
} else {print "Sorry, no records were found!";}
?>

Also, if I want the results to appear within my site template (particularly within a certain table) can I add the php code within the opened table and close the table at the end of the php?

View Replies !
Searching Multiple Mysql Columns
I'm currently building a database of local businesses, I'm quite new to using php and mysql. While I'm mostly managing to stumble my through it, a couple of things are confusing me. This is one of the things. If anyone can help, that would be really great.

Ok, so I've build a search page, and a results page and it works great but there is one problem. Currently it will only search through the 'name' column, but I'd also like it to search through the 'type' column at the same time.

This is the code I'm using to fetch the results
$colname_Businesses = "-1";
if (isset($_POST['search_par'])) {
  $colname_Businesses = $_POST['search_par'];
}
mysql_select_db($database_HBBA_DATABASE, $HBBA_DATABASE);
$query_Businesses = sprintf("SELECT * FROM Businesses WHERE name LIKE %s", GetSQLValueString("%" . $colname_Businesses . "%", "text"));
$query_limit_Businesses = sprintf("%s LIMIT %d, %d", $query_Businesses, $startRow_Businesses, $maxRows_Businesses);
$Businesses = mysql_query($query_limit_Businesses, $HBBA_DATABASE) or die(mysql_error());
$row_Businesses = mysql_fetch_assoc($Businesses);

I'm not sure what to add in to make it also search through the 'type' column or where to put that. Can anyone point me in the right direction?

View Replies !
Ignore Spaces When Searching Mysql
I've built a search that works but relies on the users to input their query very accurately. The data they're searching on are serial numbers which come from a big data feed.

Product - Code
10mm Steel Pole - TS 200-10
20mm Steel Pole - TS 200-20
....
...

What happens is people are typing in "TS200-10" and this it's coming up with zero results. One way i've solved it is to run through the table and strip out the spaces with php and save them in another column, but i'd rather use a cleaner method if it's possible.

View Replies !
Searching Multiple Mysql Rows
I have simple LIKE %term% query, working on various other scripts. I'm also trying to incorperate it in a bigger project.

I'm running a db on a MMORPG game, for all of it's "shops". I have several "colums" I want the script to look in, such as "shopname, items" and so forth. With multiple Item feilds (30 total). Code:

View Replies !
Searching Mysql For Relative Results
I am trying to make a search engine for my cms, but I have never attempted something like this before, and a unsure of how I would go about doing it, I want it to be ablt o search a specific column (in all rows) for phrases that match whats inputted into the search form.

View Replies !
MySQL Full-Text Searching
I am reading this article that says by default, the ft_min_word_len is 4 characters and the ft_max_word_len is 84 characters. I don't have access to the MySQL configuration file, is there a way to change the full-text word length settings like using .htaccess?

I access my MySQL using phpMyAdmin, which is shared with a bunch of other users. So I have no rights to make modification whatsoever. Is there a way to modify just my table in there?

View Replies !
Searching A Mysql Column Against Multiple Variables
I have an array of zipcodes which I am trying to check against a mysql table. I want to search in the column "zipcode" in a table of a bunch of entries. I want to search each rown to see if the value of the zipcode column is listed within my array.

This could be said vis vera, that I want to check the mysql table to see if any of the rows have one of the values from the array inside the zipcode column.

I've tried the statement

"select * from table where zipcode IN ('$zipsearch')", but it seems to return an odd sequence of data. It doesn't seem thurow enough.

similarly the entire statement is :
select * from table where description like "%$trimmed%" OR title like "%$trimmed%" AND zipcode IN ('$zipsearch') order by date"

I can't seem to get the statemtent to break up my requests right so that the logistics of teh statement are :

select from table where (descriptions like variable or title like variable) AND <zipcode search problem>

View Replies !
MySql Search Question. Searching On Keywords
How do site searches work?

I want to create a MySQL database with a field called "keywords". Then a
form with a search phrase input box.

I can't figure how to get the results with multiple words using php sql
query. It's easy with just one word. Do you have to run multiple queries
based on each word in the query? Then compile each of the results removing
duplicates.

View Replies !
Searching A Mysql Database For Words From A String ...
I am trying to allow users to search a mysql database by first name, last name, or subject heading. I have the search working if the people use only one word, but I can't get a string to work. If I implode the string to an array then iterate through the array I end up losing the benifits of the "group by" clause.

I have an article, subject, name, peoplelookup and subjectlookup table, and the select statement I am currently using is as follows:(sorry I don't know how to make this thing tab) PHP Code:

View Replies !
If A Mysql Db Table Is Updated For FULLTEXT Searching
When you want to do full-text searching, you have to update your table with a command like this:

ALTER TABLE articles ADD FULLTEXT(body, title);

I was wondering once I've altered my table for fulltext searching, can I still use that table for REGULAR searching using for example, "SELECT * FROM articles WHERE body LIKE '%$keyword%'";? Code:

View Replies !
Writing And Searching Calendar Date With Mysql
i am trying to write an appartment booking script I have this form with two text fields with a date in it and write this to a database for example:

my appartment is booked for 01-01-2005 till 01-02-2005

how can someone search the database for dates that are booked or not booked

so if someone searches for 01-01-2005 till 01-02-2005 or parts of this period then the text "appartment is booked" must appear else the text "appatment is free" must appair

what should the code look like for writing the dates to the database and what should te code look like for searching the database.

View Replies !
Searching MySQL Database Search Fields
I have got the basic search elements working, but what is happening is this, if you don't enter any search criteria into any of the search fields the search returns all records, which i don't want to happen, if nothing is entered in to the search field I don't want any thing displayed. Below is a snippet of the code I am using

<table>
<tr><td align=right>Search Birth Name :</td><td> <input type="text" name="FULLNAME"></td></tr>
<tr><td align=right>Search Married Name :</td><td> <input type="text" name="MARRIED_NAME"></td></tr>
<tr><td><input type="submit" name="submit"></td></tr>
</table>
</form>
</center>

<?php
include ("connection.php");

$FULLNAME = htmlspecialchars($FULLNAME);
$MARRIED_NAME = htmlspecialchars($MARRIED_NAME);
$query = "SELECT * FROM ADDRESSES WHERE FULLNAME LIKE "%$FULLNAME%" LIMIT 200";
$query2 = "SELECT * FROM ADDRESSES WHERE MARRIED_NAME LIKE "%$MARRIED_NAME%" LIMIT 200";

View Replies !
Pagination And Dropdown Menu Used In Searching Mysql
I am working on building a database made for searching. I have a text search and a dropdown box used for searching different table collumns (lets people search for certan criteria). I have that working correctly.

I also only want to show 25 results per page. I have that working correctly. My problem is that when I combine the two it breaks the code. The pagination works fine without the dropdown and vice versa. I think it is due to the variable that is being used to choose the collumn in the sql query. Code:

View Replies !
Searching Mysql Database - Searches With Options For Boolean And Normal
i and have started building my first database driven site. The database has 8 tables that contain info on my shop in Portugal. I have finished off 90% of the sites interaction with the database and the last thing i want to do is a simple database search. i.e a text field and button on the home page that will search the entire database for keywords, if those keywords are found in the title or description of any of my entries they will display the results on a new page.

I have tried looking for tutorials but all i have found are complex searches with options for boolean and normal (which i do not want). Can anyone point me in the direction of a tutorial that produces a simple multi column, multi table search that displays results.

View Replies !
Joins
I'm trying to figure out how to create my join so that only records with a matching date_id are returned. Here's what I have so far:

$sql6 = "SELECT * FROM team_members LEFT JOIN team_members_x using (team_id)";

The team_members_x table has a date_id field that relates to a third table called 'dates'. Later on, when I attempt to put the values from $sql6 (now called $result6) into a <select> form box using the following code, I run into problems which I'll describe below:

while ($row = mysql_fetch_array($result6)) {
$team_id = $row['team_id'];
$date_id = $row['date_id'];
$team_fname = $row['team_fname'];
$team_lname = $row['team_lname'];

if ($team_id != NULL) {
$option_block6 .= "<option value="$team_id" selected="selected">$team_fname $team_lname</option>";
} else {
$option_block6 .= "<option value="$team_id">$team_fname $team_lname</option>";
}
}

I'm not getting what I want. What i want is one value from each entry in the team_members to show up with only those members that were previously chosen for this record to be highlighted in the list. However, what I'm getting instead is multiple entries for each team member with each team member multiply selected. Am I doing something wrong with my join syntax? Or is the problem with my while loop?

View Replies !
Inner Joins
OK I may be doing this completley wrong but is 'seems' ok but I only get one row back
the JOBLOGS table just contains userID,Date started, date finished, jobID the other tables contain more details about the taks or project Code:

View Replies !
Joins VS Subqueries
Can anyone please tell me in which cases sunbqueries are efficient than
joins and vice-versa? I googled about it. Few sites informed that subqueries are efficient than joins only "When the sub-query contains one or more aggregates".

But most of the sites ensured that joins are efficient than subqueries
in most of the cases.

I am assuming like this:

When we have small database,better to use jojns instead of subqueries.
Because,join performs combining of all possible columns(since we have
small database), then applies join condition, then filters and shows the results.

When we have large database,better to use subqueries instead of joins.
Because, Joining of corresponding columns and then filtering is not
efficient with large database.

Is my assumption correct?

View Replies !
Joins Of A Sort
I have two tables. 

1. with a list of airports, and their codes.
2. with a list of flights, with flight data and airport codes.

I have a query which is working fine in gathering all the flight information from table 2.  Now, when i post the data in a table, i want to show the name of the airport, however, in table 2, it doesn't contain the name of the airport, only the airport code.

I want to get the airport name from table 1, while still maintaining the error free query that i have mentioned above.

I've tried the Select `table1`.*, `table2`.* from `table1`, `table2` where Working query AND `table1`.airportcode = `table2`.aircode order by what-ever.

and try to post the data from table 2, but i get no results where as before i got some.

View Replies !
Joins - Three Tables
the SQL syntax to join three tables. tableA contains a column 'aLocation' which I need to look up in 'bLocation' in tableB. tableB also has a colum 'bDistrict' that allows me to look up other data in tableC.

How can I do a SELECT on tableA joining to tableB and in turn, looking up the correct row in tableC? There is a possibility of null fields in the 'aLocation' column of tableA.

View Replies !
Query And Joins
So im having a little trouble understanding how to deal with this query I have two tables:

qualityadmin:
qualityadmin_id (auto_increment - this is my primary key)
authority_body
address1
address2
etc

and

activity_participant

activity_participant_id
refno
qualityadmin_id
activity

what is supposed to happen is that the participant fills in a form that populates part of the qualityadmin table. The participant can choose one or activities from a list box. These choices are recorded in activity_participant table. My question is how can I run a query that shows all authority_body's that have an activity of X (e.g. Government & statutory) Does this make sense?

View Replies !
Tutorial On Joins
I keep hearing about joins and seeing them mentioned in the posts, but I'm afraid that they still don't make any sense to me. Can someone point me to a book or tutorial on the subject? Would I look in the PHP manual or a database book?

View Replies !
Table Joins
I have an activity table which has A_ID (PK), C_NUMBER (FK), A_DATE, A_DESC, and a MEDIVAS field. When I perform a search by date, all the dates in that column show up in a combo box, when a cerrtain date is selected, I'm trying to output all the info for that activity (description, medivas) as well as the coresponding company information (C_NUMBER) would be its unique identifier.

View Replies !
Using Joins Effectively.
Basically, i am trying to display data received when i query using Joins. Basically i am bringing back client info, there is only one of these and I am then Joining two other tables on the client_id.

I c an bring back data fine, even quite impressed, the only problem is how do i get to the second, third etc returned rows of the of the other tables.

I mean, there is only one client, but the history and contact tables have multiple rows with the same id. Code:

View Replies !
Understanding JOINS
My admin roster I can click on his name to pull up the editsoldier page but none of his data is there because it can't match the weapon_id. PHP Code:

$result = $db->sql_query("SELECT * FROM " . $prefix . "_milpacs_members mm JOIN " . $prefix . "_milpacs_units mu  JOIN " . $prefix . "_milpacs_weapons mw WHERE mm.uniqueid ='$id' AND mm.unit_id = mu.unit_id AND mm.weapon_id = mw.weapon_id");.

View Replies !
Database Design JOINS
I have a table called courses with the following fields:

Coursecode (primary key & auto_increment), briefdesc, aimed at etc

I have created another table called courseaims:

Courseaimid (primary key & auto_increment) coursename.

One course has many courseaims. In my form that inserts/updates courseaims, I currently have a dropdown field which searchs for all the coursenames in the table coursename. An insert is then made but here is my problem.

As it stands I am adding lots of courseaims for one course but as a result the field coursename in courseaims table has lots of instances of the same coursename. This is a waste and I can normalize this surely. How can I improve this situation and if JOINS are a solution-which type.

View Replies !
Table Joins Output
I've been thinking a bit about how to handle result sets when you join tables in one-to-many relationships. Let's say we have a users-table, and a messages-table. The users-table has a one-to-many relationship with the messages-table. When you join them, you get something like this as a result: Code:

+--------+----------+-----------+---------+
| UserID | UserName | MessageID | Message |
+--------+----------+-----------+---------+
| 1 | Bob | 1 | Hi! |
| 1 | Bob | 2 | Hello! |
| 1 | Bob | 3 | Wow! |
| 2 | David | 4 | Hey! |
| 2 | David | 5 | Hey you |
+--------+----------+-----------+---------+

Now, if I want to display this, and only show the username one time, what is the best way of doing this? Should I store the user id in a temp variable, and check in the loop if it has changed, or is there a more convenient way of doing this?

View Replies !
Joins/Advanced SQL Concepts
I'd like to learn some advanced SQL concepts so that A) I understand them here on the board (if you notice, I tend to stay away from the DB forum ) and B) when the need arises, I can use them without hesitation. what type of data/database structure might be good for learning joins and more advanced SQL concepts?

What I mean is this right now, I have no databases that use joins, nor can I think of any that will allow me to experiment with joins effectively. So what types of databases would be good? Like: library (check in/out system, reference books in one table and checked out in another), company, etc. I'd obviously be putting in some fake data so I can try to learn more about them.

View Replies !
Joins And Same Field Names
What do do when you have some Joins in your sql and databases with similar field names. How do i make a distinction between the ones with the similar names. EG: PHP Code:

$sql = "SELECT c. * , f. * , l. *
FROM csite_companies c
LEFT JOIN csite_filerefs f ON ( c.id = f.compid )
LEFT JOIN csite_locations l ON ( c.id = l.compid ) WHERE
LIMIT 0 , 30";
$recordset = mysql_query($sql) or die(mysql_error());
$count = 1;
$count2 = 1;
        while ($results = mysql_fetch_array($recordset))
                    {
                             if($count2==1) {
                             $company['id'] = $results['id'];
                               }

Problem being that all 3 tables have an id field and i want the one from the company table.

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved