Jump to content

[SOLVED] Variables + Variables in a loop


law

Recommended Posts

Ok here is what im doing.. and i have no idea how to do it this was just my best guess..

 

Im selecting a array and then im using that array to select another array.. soo how do i do that here is a sample of what my current code looks like

 

for ($num=1;$num=$num_rows;$num++){
//=====Sql Querys ect======
$title[$num] = titlerow[title];
$titleminnumber[$num] = titlerow[minnum];
$titlemaxnumber[$num] = titlerow[maxnum];
//=====title is now pulled from database===
     if ($titleminnumber[$num] != null){
          //use the numbers in a query to call specific rows from another database
          //this is where the second array is produced
          $i = $titleminnumber[$num];
          while($i <= $titlemaxnumber[$num]){
               $data[$num][$i] = $datarow[id];
               // this is where im lost what is the proper syntax for the above line?
               $i++;
         }
     }
}

 

this is just a sloppy example of what im doing sorry! hope its close enough

Link to comment
Share on other sites

If you are quering two tables in different queries then you should look into normalizing your database so you can use SQL JOINS. With JOINS you can query multiple queries in one query. This is alot more easier than running two separate queries and trying to merge the results

Link to comment
Share on other sites

ok im sure this is not the place for this question but can you give me an example of what a joined query would look like or do? I think i have the idea but i learn best through examples

Link to comment
Share on other sites

interesting.. great.. ok let me explain what im doing with the above code maby you can point out something im not seeing... because i don't know how to normalize this database.. I'm making a photo gallery of sorts.. the idea is that the user can choose what pictures from the database that they want to show up on their gallery and then name their own gallery.. the idea is that the small community (just a local college group website.. nothing fancy.. they can put up all their photo's and make a gallery of events from the way they remember their night/event being) so the pictures are all indexed in the database.. but they don't really have a foreign key (as of now) the user just creates a gallery in the gallery table and then once they choose the pictures it puts the picture id's into the gallery table and that becomes my foreign key to use in the other query to pull the pictures..

soo thats my issue i need a variable that knows what the gallery it belongs to and what picture goes in said gallery soo my variable would have to look something like

$gallery[$num].$picture[num]

except that variable won't work?

Link to comment
Share on other sites

ok i slept on it.. and now it makes since.. programming all night is over rated! or maby im just terrible at it.

anyway.. here is what i need to be my new sql query.. can anyone tell me how this "should" be written because its currently not working correctly

 

SELECT *
FROM Gallery, Images
WHERE Gallery.imgminid = Images.id 
AND Gallery.imgmaxid >= Images.id 
AND Gallery.ID='1'

 

the imgminid and the imgmaxid are intended to provide me with the range that the user wants within their gallery once i have this working ill work on expanding and improving the idea i just need an example that works for now.. so can anyone tell me how to add multiple clauses to a WHERE statement? in this code so that i can begin the process of rewriting my php code

Link to comment
Share on other sites

SELECT *
FROM Gallery, Images
WHERE Images.id
BETWEEN Gallery.imgminid 
AND Gallery.imgmaxid
AND Gallery.ID='1'

 

i got the concept down.. now i just have to refine it.. thanks guys.. problem solved

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.