law Posted May 8, 2008 Share Posted May 8, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/104756-solved-variables-variables-in-a-loop/ Share on other sites More sharing options...
wildteen88 Posted May 8, 2008 Share Posted May 8, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/104756-solved-variables-variables-in-a-loop/#findComment-536244 Share on other sites More sharing options...
law Posted May 8, 2008 Author Share Posted May 8, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/104756-solved-variables-variables-in-a-loop/#findComment-536251 Share on other sites More sharing options...
wildteen88 Posted May 8, 2008 Share Posted May 8, 2008 Have read of the following Basic JOINS tutorial. The following article goes more in depth Quote Link to comment https://forums.phpfreaks.com/topic/104756-solved-variables-variables-in-a-loop/#findComment-536257 Share on other sites More sharing options...
law Posted May 9, 2008 Author Share Posted May 9, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/104756-solved-variables-variables-in-a-loop/#findComment-536424 Share on other sites More sharing options...
law Posted May 9, 2008 Author Share Posted May 9, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/104756-solved-variables-variables-in-a-loop/#findComment-536660 Share on other sites More sharing options...
law Posted May 9, 2008 Author Share Posted May 9, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/104756-solved-variables-variables-in-a-loop/#findComment-536667 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.