Jump to content

Echo Results


barney0o0

Recommended Posts

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 ?

Link to comment
Share on other sites

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:

  1. Get {fields} from database where {condition}
  2. Check for error in query.
    1. If error, show message
    2. Abort showing items.

[*]Define template for output.

[*]Loop through rows from result.

  1. Do some calculation.
  2. Escape data.
  3. Add to output via template.

And so forth.

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.