Jump to content

HELP!!! With optimizing mySQL statement


eliZZZa

Recommended Posts

Hi php freaks,

I am addicted, but unfortunately no pro yet.

So I kindly ask for your help.

I wrote a mySQL statement, which works, but I am sure, there is a more efficient way to write this. Could you please help?

 

//Request crime_country

$personid = $myrow["id"];

$countryid = mysql_query("SELECT destinationid FROM crime_countries WHERE sourceid = $personid");

$country = mysql_fetch_array($countryid);

$countryshort = mysql_query("SELECT shortname FROM countries_all WHERE id = $country[destinationid]");

if ($countryshort != NULL) {

$countryshortarr = mysql_fetch_array($countryshort);

printf ("<div id=\"flag\"><img src=\"http://www.crimeZZZ.net/images/flags/%s.gif\" /></div>\n", $countryshortarr["shortname"]);

}

//Ende Request

 

Thank you in advance and kind regards from Austria

eliZZZa

http://www.crimeZZZ.net/

A sample listing using the above statement can be viewed under

http://www.crimeZZZ.net/serialkiller_index/xtemplate_a.php

Link to comment
Share on other sites

Well you can do this:

 

SELECT 
crimeC.destinationid, allC.shortname
FROM
crime_countries crimeC
JOIN countries_all allC ON crimeC.destinationid = allC.ID
WHERE crimeC.sourceid = $personid

 

I think that is right although I haven't tested it...

 

Link to comment
Share on other sites

Well you can do this:

 

SELECT 
crimeC.destinationid, allC.shortname
FROM
crime_countries crimeC
JOIN countries_all allC ON crimeC.destinationid = allC.ID
WHERE crimeC.sourceid = $personid

 

I think that is right although I haven't tested it...

 

 

Hi Shamilton,

first of all, great thanks for your prompt reply.

 

I don´t get it running (sorry for being sooo dummy  :'(

I wrote the following (did I get it right?):

 

$personid = $myrow["id"];

$countryshort = mysql_query("

SELECT

crimeC.destinationid, allC.shortname

FROM

crime_countries crimeC

JOIN countries_all allC ON crimeC.destinationid = allC.ID

WHERE crimeC.sourceid = $personid");

if ($countryshort != NULL) {

  printf ("<div id=\"flag\"><img src=\"http://www.crimeZZZ.net/images/flags/%s.gif\" /></div>\n", $countryshort["shortname"]);

  }

  else {

  printf ("\n");

  }

Link to comment
Share on other sites

As it starts with

 

$personid = $myrow["id"];

 

it looks like there is potential for another join in there to bring in the original table containing "id"

 

 

Hi Barrand,

thank you for your reply too - it sounds promising, but I don´t know, how to use your comment  ???

 

eliZZZa

Link to comment
Share on other sites

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.