barney0o0 Posted September 28, 2012 Share Posted September 28, 2012 Hi chaps, its been a while since i did some coding.... im stumped... I need to echo out all results in 'page' table. These 'pages' have thumb images pulled from another table 'images'. The page.img has the same value is as images.cid So for example, the ideal would be: <?php do { ?> page.title page.text images.cid (1), images.cid (2),images.cid (3) <!-- i need to echo all images with image.cid the same as page.img --> <?php } while ($row_query = mysql_fetch_assoc($query)); ?> How do i bring in all the images from images.cid with the same value as the actual page.img ? Quote Link to comment Share on other sites More sharing options...
White_Lily Posted September 28, 2012 Share Posted September 28, 2012 just curious, why do you have page.title, etc outside of the php tags? Quote Link to comment Share on other sites More sharing options...
barney0o0 Posted September 28, 2012 Author Share Posted September 28, 2012 ?..arent they within the echo to repeat through all the records? Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 28, 2012 Share Posted September 28, 2012 There is no echo in your code. Quote Link to comment Share on other sites More sharing options...
barney0o0 Posted September 28, 2012 Author Share Posted September 28, 2012 ah, ok it should be ' <?php do {' ...but anyways, the head melt is the mysql query.. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted September 28, 2012 Share Posted September 28, 2012 That's not an echo, that's a loop construct (known as a do-while loop). In addition to that, the do-while loop is the wrong loop to use in this case. As the first run through the code block will be without having access to the data you wanted, something which will cause problems. Not to mention, your variables are not defined anywhere, nor are they actual variables. At least not in PHP. The only variable you have there is not used in your code at all, and that's the $row_query variable. Seeing as we don't know the query either, we have no idea what kind of information is stored inside it. So why you didn't post it, especially considering your comment about it being the "head melt", is quite perplexing. As well as a huge disservice to yourself. The reason you're getting output to your browser is because you terminate the PHP mode, which causes everything in between to be sent directly to the browser. Without any parsing from PHP at all. Meaning it'll be static text repeated as many times as you have rows in your table, plus one. What's clear, at least, from the code you've posted, is that you have no idea about what you're doing. I really recommend that you go back to the basics, read up in the PHP manual language reference. At least down to, and including, the chapter about Functions plus the chapter about Predefined Variables. Once that's done you should sit down and think though exactly1 what you want the code to do, in the smallest step. Then write it down in a keyword list, so that you can see the flow of the logic, before you start coding. Once you've done that, you should find that the actual coding is quite easy, as you should have solved all the issues in the planning faze. 1 When I say "exactly" i mean exactly, not just "show all rows", but every single step needed to get those rows, format them, and sending them to the browser. Like this: Get {fields} from database where {condition} Check for error in query.If error, show message Abort showing items. [*]Define template for output. [*]Loop through rows from result. Do some calculation. Escape data. Add to output via template. And so forth. Quote Link to comment 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.