Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query question

Status
Not open for further replies.

xWastedMindx

Technical User
Sep 3, 2002
67
0
0
US
Hello again.

I've seen this asked before.. but it was never clearly answered.

When pulling multiple tables (2 of them), and a bunch of information out of each through a query...
Is there a way to just use the Auto-Incrementing "ID" to grab all the info, instead of appending each and every field onto my query statement?

eg. -- I'd like to do something like this:
$result = mysql_query
("SELECT dvd.dvd_ID, images.img_id, FROM dvd, images WHERE dvd.dvd_ID = images.img_id") or die(mysql_error());

And this for my main HREF link to pull the info.
echo (&quot;<a href='./spread.php?dvd_ID&img_id'>link</a>&quot;);

And the above query would then pull everything from the database and I could then insert what I need wherever in the following pages.


But instead, I have to use this:
$result = mysql_query
(&quot;SELECT dvd.dvd_ID, dvd.dvd_Name, dvd.dvd_Price, dvd.release_Date, images.img_id, images.img_file
FROM dvd, images WHERE dvd.dvd_ID = images.img_id&quot;) or die(mysql_error());

while ($row = mysql_fetch_array($result)) {

$dvdID = $row[&quot;dvd_ID&quot;];
$dvdName = $row[&quot;dvd_Name&quot;];
$dvdPrice = $row[&quot;dvd_Price&quot;];
$img_id = $row[&quot;img_id&quot;];
$img_file = $row[&quot;img_file&quot;];
$releaseDate = $row[&quot;release_Date&quot;];

echo (&quot;<a href='./spread.php?dvdID=$dvd_ID&dvd_Name=$dvd_Name&dvd_Price=$dvd_Price&img_file=$img_file&release_Date=$release_Date'>link</a>&quot;);
}

I just find it very tedious, because I'm still adding to my database little by little.. as it grows...with new colums and information to be inserted, and I find that I have to go back and edit all the different queries and such. It'd be much easier if I could just use the ID to grab everything, especially for my main HREF link (above)

So is it possible, or no? I'm thinking Sessions.. but I don't know much about that yet.

&quot;Hey...Where are all the chicks?&quot; -- unknown
 
You can do this:

Code:
$result = mysql_query(&quot;SELECT * FROM dvd, images WHERE dvd.dvd_ID = images.img_id&quot;) or die(mysql_error());

However, I strongly recommend against doing that, as you will most likely never use all the fields. It more resource efficient to explicitly declare which fields you want to pull in, it's also easier to read the code that way.

Take Care,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top