Current location: Hot Scripts Forums » Programming Languages » PHP » tables and PHP, odd question


tables and PHP, odd question

Reply
  #1 (permalink)  
Old 07-01-04, 09:07 PM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
tables and PHP, odd question

Hello , i have a question, --this isnt the whole script, its a section i cant figure out--
I have two tables, one could be called, cars, and another carlocations, all locations having an ID.
So a person searches the DB cars, and finds a car he likes. He clicks it to display more information about it. Then it says where you can buy the car.

Is what i want to do is list all the locations in carlocations, and then in cars, have a column called, locations.

When i INSERT a car into the table, in the locations column, i type all the ID numbers of all the locations that hold the car.

Ok, now when i INSERT the IDs, lets say I *try* 1, 6, 10, 11, and perhaps w/o the commas, just 1 6 10 11

Can i have PHP do something like this:

Code:
$SQL = "SELECT * FROM cars WHERE id LIKE '$carid'";

$result = @mysql_query($SQL) or die("Could not run query");

while($row = mysql_fetch_array($result))
{
$anotherSQL = "SELECT * FROM cars WHERE id LIKE '$carid'";

$result = @mysql_query($anotherSQL) or die("Could not run query");
echo("<a href="carsearch.php?locations=$locationid>$locatio nsname</a>
// -----PHP would then see spaces in between the numbers, and for each space, it continues the while loop, chaning $location to the number after the space. So technically it would be doing this.

Locatoin Name(would (ID =1)
Locatoin Name (ID =6)
Locatoin Name (ID =10)
Locatoin Name (ID =11)
I know a lot of variables wernt specified, but this is just to show how i would want it to work. Perhaps there is a better way, i just dont want to make 100 columns, each being: location1, location2, location3, and then in the colum it gives 1 number.

If there is anything that could work similar to this, please post, i think the design i said is probably not possible.
---Thanks
Reply With Quote
  #2 (permalink)  
Old 07-02-04, 01:22 PM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
you cant use LIKE in that.

use where id = '$var'

and a LIKE has to be %LIKE%
Reply With Quote
  #3 (permalink)  
Old 07-03-04, 10:42 AM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
could anyone answer my question? Because my old question was kind of hard to read, ill do another brief description:
Table: carlocations COLUMNS: locationID(auto), locationName, locationURL
Table: cars COLUMNS: carID(auto), carName, carLocationsList

A user searches through the database of cars (this script is done), and finds a car he likes, lets call it the Dodge Viper.

He then clicks it to find more information about it. The display.php page comes up, with all the information, including all the locations which this car is at.

Now, the question: How do i make that car list?
There would be a ton of cars in the DB, and about 150 locations, each car varrying in locations.

Is what I wanted to do, is in my Submitform.php (for the cars), type all the ID's of the carlocations, and then when i go to display.php, all the ID's typed in will be:
SELECT from carlocations WHERE locationID = '$one_location';
echo ("<a href='cars/$row[locationURL]>$locationName - FIND OUT MORE ABOUT THE LOCATION!</a>");

This wasn't real brief, but i think it was much easier to understand.
Reply With Quote
  #4 (permalink)  
Old 07-04-04, 12:30 PM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
I take it no body knows?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Php with flash or without tables ? EraseR PHP 0 06-26-04 07:36 AM
speeding up the creation of tables davidklonski PHP 1 06-01-04 03:19 AM
Need help counting tables (selected db) DBN PHP 2 05-13-04 02:12 AM
error when creating database tables with php script spiroth10 PHP 4 01-06-04 03:59 PM
PHP Regular Expressions Question linuxmaster1979 PHP 0 12-18-03 09:58 AM


All times are GMT -5. The time now is 05:08 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.