|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
consistant not
Can someone tell me why in this code, the images are displayed and text displayed wrong. They appear like this:
Image1 Image 2 - Description of image 1 Image 3 - Description of image 2 PHP Code:
I have been agonizing over this the past 5 days and cannot seem to get it working in sync. I think it has to do with ID starting with 1 and fields starting with 0 but I dont know how to solve it. I need someone to help....I can email the full code if necessary. Thank you for your help. -Steve |
|
#2
|
||||
|
||||
|
Have you tried starting your for loop with $id=0 rather than $id=1? Seems an obvious starting point. On another note, you might want to reconsider how you're building your links. By passing the table name in the query string, you're allowing users to control what data they have access to. You may mean for them to grab data from the images table, but a malicious user could fiddle with the URL, set the table param to "auth" and have sudden access to data he shouldn't. As a minimum precaution, you should have a list of tables accessible from this script and check the passed table value against this list before running the query. And you should validate $id to make sure it's an integer.
For example, imagine I changed the query string so that my value for $id was: PHP Code:
Instead of a list of photos with titles and descriptions, I might have a list of usernames and passwords from your user database, provided I had guessed the field and table names correctly, which typically isn't hard to do. Or if my example doesn't work precisely in this case, you can see at any rate how careful you should be about taking user input. |
|
#3
|
|||
|
|||
|
I have tried looping from zero and the Image has an ID of 0, but the ID actually starts with 1 so there is no image to display, and the text displays on ID 2 even though it is in row 1.
|
|
#4
|
||||
|
||||
|
I'm a little curious: Why are you doing it this way to begin with? Typically, you'd do a query and, for each query result, print a row. You're entering a loop and then running a query for each loop iteration, adding to overhead and apparently causing a bizarre id misalignment problem. Is there a good reason for this?
Might you consider doing something like: PHP Code:
I know my code doesn't precisely emulate what you've got, but you see what I mean. I don't understand why you've got the nested query or the extra queries at all when you should be able to achieve your result much more easily. Can you explain your motivation? |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > consistant not |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|