Log in

View Full Version : New to SQL



Diversions
06-23-2008, 02:19 PM
I am starting the process of learning MySQL through W3 Schools and going to develop it on a WAMP localhost. By and large it seems straight forward enough BUT - before I make a complete hash of it I have what I know will be a very elementary question.
When I call up the db into the web site, I will want the images and product names linked to an outside URL. When I set the db up do I place the information directly in the field (i.e: <URL-TAG>Product- A</a> or am I calling the information from two distinct cells of the db (i.e. a column with the URL and a column for the Product Name)?
I realize this is basic stuff, but it will clearly help me get my head around this dbase process since I have never developed one before.

Thanks
D

allahverdi
06-23-2008, 05:36 PM
I don't know if i understood you correctly, but let me answer.

"I am calling the information from two distinct cells of the db" - this. For url one and for product name other one.

Diversions
06-23-2008, 06:52 PM
To be clear Allahverdi, in html when one requires an image or text with a link it is set up <a href="http://www.xyz.com" title=""><img src="images/pic.jpg"</a>
So my question is this! How is the image column merged with the URL to gain the same effect in MySql.
Hopefully, I did a better job of explaining it this time out.

Many thanks
D

allahverdi
06-24-2008, 04:24 AM
Then i said correct. Your table will be like this:

imgsrc | url
-------------------------------------
images/pic1.jpg | http://www.xyz.com
images/pic2.jpg | http://www.ccc.com
images/pic3.jpg | http://www.dsd.com

If you are doing it with php, your query will be like this:



<?php
$result = mysql_query("SELECT * FROM mytable");
while($rows = mysql_fetch_array($result, MYSQL_ASSOC)){ //this will get all rows
$img = $rows['imgsrc']; //imgsrc coloumn
$url = $rows['url']; //url coloumn
echo"<a href=".$url."><img src=".$img." /></a> <br/>"; //echo image and url
}
?>


Output will be:



<a href="http://www.xyz.com"><img src="images/pic1.jpg"/></a>
<a href="http://www.ccc.com"><img src="images/pic2.jpg"/></a>
<a href="http://www.dsd.com"><img src="images/pic3.jpg"/></a>


This output is just it's source. But it will be like image and when you click it goes to that url.

I wish it will help you.