Reputation Activity
-
missindependent got a reaction from Kaskhautual in Selecting multiple values from a databaseOk let me see how to explain this:
I have a database with shoes and sock with a cost. The user goes thru and a series of steps in a form and it saves to the database.
I wrote calculations that calculates the cost of a shoe and the cost of a socks but i worked it out on a sheet called 'total.php'.
$nike, $reebok and for socks $blue, $red
So a person can choose a nike shoe and blue sock, or a nike shoe and red sock. Or the person can choose a reebok shoe and a blue sock or a reebok shoe and red sock.
So i use a select statement to recall what was chosen : SELECT * FROM Choice where memberid = $userid; and this works.
What do i do next: Do i use an if, else statement??
My predicament is how do i go about selecting the cost of a shoe and sock and echoing the results on a separate sheet?
-
missindependent reacted to andy9l in Selecting multiple values from a databaseUsing my table structure, you would use a query along the lines of:
SELECT shoes.name as Shoe, socks.name as Sock, (shoes.cost+socks.cost) as TotalOrderCost, choices.MemberID as MemberID FROM choices JOIN shoes on choices.ShoeID = shoes.ShoeID JOIN socks on choices.SockID = socks.SockID WHERE choices.MemberID = 1Switch the MemberID accordingly.
That will return the following result:
+---------------+------------+----------------+----------+ | Shoe | Sock | TotalOrderCost | MemberID | +---------------+------------+----------------+----------+ | Nike Shoe One | Blue Socks | 15.98 | 1 | | Nike Shoe Two | Red Socks | 14.98 | 1 | +---------------+------------+----------------+----------+ -
missindependent reacted to Chris Day in displaying images in a webpage using phpyou can either do it like this
// if you are not outputing the html via php echo.print <td><img src="showimage2.php?id=<?php echo htmlentities($_GET['pic']); ?>" title="tan" width="150"height="150"/></td> // Or if it is outputed by echo/print echo '<td><img src="showimage2.php?id='.htmlentities($_GET['pic']).'" title="tan" width="150"height="150"/></td>'; // The above code will allow you to put &pic={id} in your URL so you can select a certain image //Or if you wanted to pull all the images from the database and display them like a gallery you can use a while loop like so $query = ""; // Select the images from the database using your preferred method, mysql(i), PDO etc... while ($img = $query_array) { // As above turn the query into an array using your preferred method echo '<td><img src="showimage2.php?id='.$img['id'].'" title="tan" width="150"height="150"/></td>'; } -
I think you are actually using the wrong method!, you need to put tpgether a script which can dynamically list images from ids,
For instance:
I have a product with the id:0001
I can create a folder so that when i associate or upload images for that product it will rewrite the filename like so:
IMG:1{
0001_1T.jpg
0001_1M.jpg
0001_1L.jpg
}
IMG:2{ ##for the same id, so now product id:0001 has two images, each image has thumbnails, medium and large pictures
0001_2T.jpg
0001_2M.jpg
0001_2L.jpg
}
So before the underscore idetifies the product it is related to, after the underscore we have the 1st picture and then "T" which means thumbnails, M= medium pictures, L=larger picture.
This way you can manage images easily!
you need a function/loop which first searches to see if picture already exists!
Find out how many pictures exist for that id,
And then you can start the script again from the number counted so " 0001_".$i." " etc... so if i did a check on id:0001 again it will return
IMG:3{
0001_3T.jpg
0001_3M.jpg
0001_3L.jpg
}
So as you can see it is quite dynamic and flexible! Because there is a set pattern where you can design a function to look for images and display them as they should.
This is the simplest way i can tell you, and it's the best way i can see, i can go into more detail, but i think that is enough for you to understand?
I have a script which i have written which does all this for me, i can show you small snippets of it, or you can show me what you have written and see where we can change it to improve on it?