PDA

View Full Version : Image retrieval (MYsql) and horizontal loops??


confucious
08-28-2008, 04:44 PM
Hi everyone - could really use some advice on a couple of issues, if anyone knows the answers:)

Item 1: A horizontally looping repeat region (four columns, two rows) for a product list page. I have abandoned Dreamweaver CS3's repeat region as it only goes vertical...I need to write it myself, I think - I am studying coding but have gone to the basics so am a little behind and trying to catch up! Dreamweaver used to have this as a behaviour, but no longer - any suggestions as to sites etc. that may discuss code/solutions for Dreamweaver for this precise problem? (and going through the tutorials here, but nothing as yet).

Item 2: storing an image link in MYsql Databse to retrieve image from site folder when page is dynamically created. Would I be right in assuming I would store the full image path <src=rootfolder/images/thumbnails/sunset.jpeg> in a fileed in MYsql and then create a get command in PHP in (or around?) the cell I want the thumbnail to appear? Ie:
<?php
// .. get data from database
<Table>
<td>
echo $imagedata; // Where this is the source of my image
</td>
</table>
?>

I know this code wouldn't work, but is it the right idea?

Woudl love any input...thanks for your time - am coming along in understanding but it takes awhile...a very LONG while (This is why real coders can make good cash!!)

confucious
08-28-2008, 08:47 PM
Okay - I managed to solve the horizontal loop problem and things are displaying the way I need for the moment...but if anyone has ideas on the MYsql database image retrieval challenge I would still love to hear! THanks in advance!

davidj
08-28-2008, 08:51 PM
regarding your image issue

you only need to store the image name

the path wont change so its right to say that you could set the path in a variable and then concatenate them both when needed

confucious
08-29-2008, 04:33 PM
As you suggested, I've started looking into concatenating a string where I want the image to appear by defining a variable (image path) and then concatenating the path variable to the thumbnail name (ie: sunset.jpg) that is inserted into the page when a user creates that page. I am having no luck at all, unfortunately...I will post code below:

1 <?php
2 $thumbLink = "<img src= '../root folder/images/thumbnails/ 'thumbnails' />";

///above is the line I want to have as a set image path for all the images used on this repeating page. The word 'thumbnails' is my attempt at telling the string to include 'thumbnails' when I insert it - see line 11///

3 $rsRings_endRow = 0;
4 $rsRings_columns = 4; // number of columns
5 $rsRings_hloopRow1 = 0; // first row flag
6 do {
7 if($rsRings_endRow == 0 && $rsRings_hloopRow1++ != 0) echo "<tr>";
8 ?>
9 <td><table width="145" class="repeatingtablestyle">
10 <tr>
11 <th height="120" scope="col"><?php echo $row_rsRings[$thumbLink . " " . 'thumbnails'] ?></th>

////above is the line I am trying to "concatenate" the strings into. I had thought if $thumbLink was defined, when the page is created and ['thumbnails'] becomes the image name (from MYsql database) the two would join and they would draw the image from my folder.
</tr>

Any and all help would be much appreciated. I think I am probably butchering it so...

Cheers.

davidj
08-29-2008, 04:38 PM
ok

your path


$thumbLink = "../root folder/images/thumbnails/";


your image

$row_rsRings['thumbnails'];

to concatinate them just do...


echo $thumbLink.$row_rsRings['thumbnails'];

confucious
08-29-2008, 04:53 PM
A bit easier than the acrobatics I was attempting isn't it? Just one question/problem - it now concatenates the strings, but only by adding the name of the jpg (which is stored as img_8467.jpg in my table) to the string of text and printing it on the page (ie: ../rootfolder/images/thumbnails/IMG_8467thumb.jpg). Do I need a command function or quotation marks to make it act on the line rather than print it?

Here's my code as you suggested:


<?php
$thumbLink = "../rootfolder/images/thumbnails/";
$rsRings_endRow = 0;
$rsRings_columns = 4; // number of columns
$rsRings_hloopRow1 = 0; // first row flag
do {
if($rsRings_endRow == 0 && $rsRings_hloopRow1++ != 0) echo "<tr>";
?>
<td><table width="145" class="repeatingtablestyle">
<tr>
<th height="120" scope="col"><?php echo $thumbLink.$row_rsRings['thumbnails'] ?></th>



Thanks again David!!

Lawrence

davidj
08-29-2008, 04:59 PM
ok its echo'ing to the page as a string

just add (concatinate) html for it to render the image inside an image tag

make sure you do this in your do{ loop


echo "<img src=".$thumbLink.$row_rsRings['thumbnails']." />";

confucious
08-29-2008, 05:18 PM
THat seems to be getting a lot closer - now they show, but as broken images for some reason. This may be a stupid question, but if it is within the repeated tabloe, is that in the DO section? It is not within the PHP tags, but it is repeated...I appreciate all this time you're spending.
New code:


<?php
$thumbLink = "../rootfolder/images/thumbnails/";
$rsRings_endRow = 0;
$rsRings_columns = 4; // number of columns
$rsRings_hloopRow1 = 0; // first row flag
do {
if($rsRings_endRow == 0 && $rsRings_hloopRow1++ != 0) echo "<tr>";
?>
<td><table width="145" class="repeatingtablestyle">
<tr>
<th height="120" scope="col"><?php echo "<img src=".$thumblink.$row_rsRings['thumbnails']."/>"?> </th>
</tr>
<tr>
<td><?php echo $row_rsRings['product name']; ?></td>
</tr>
<tr>
<td><?php echo $row_rsRings['price']; ?></td>
</tr>
<tr>
<td><?php echo $row_rsRings['item code']; ?></td>
</tr>
</table></td>

davidj
08-29-2008, 05:48 PM
if they show up broken then your path is incorrect

best way to sort this is add a pic through dreamweaver normally using the image button. Then in the code view just cut the path from that <img tag and delete the remainder of it. Paste the path in your path variable

This may be a stupid question, but if it is within the repeated table, is that in the DO section? It is not within the PHP tags, but it is repeated


no question is stupid. I respect you for learning code and i promise you will reap the rewards

regarding your question

its a common mistake

look at this example all wrapped inside PHP tags

<?PHP

$v= 1;

if($v == 1){

echo "<b>hello world</b>";

}

?>


and this which jumps in and out and in again into PHP


<?PHP

$v= 1;

if($v == 1){

?>

<b>hello world<b/>

<?PHP } ?>



they do the same job

confucious
08-29-2008, 06:46 PM
I think I should leave this alone for awhile soon as my head is spinning - I am surprised real programmers have any hair left at all with the finickiness of this stuff!! My images are still broken (show that way in "live view" in DW). I have copied and pasted the img source code as you suggested but to no avail...I also have checked my file names in both MYsql and my image folder - both are "ring". You will see at the top of the code I will paste below is the image I inserted to obtain the proper path - the only thing different is the width and height values that come along with it - could they be appearing and messing the code because of extra quotations??

////below is inserted image = proper path

<p><img src="root folder/images/thumbnails/ring.jpg" width="110" height="100" /></p>
<table >
<tr>

<?php
$thumbLink = "root folder/images/thumbnails/";
$rsRings_endRow = 0;
$rsRings_columns = 4; // number of columns
$rsRings_hloopRow1 = 0; // first row flag
do {
if($rsRings_endRow == 0 && $rsRings_hloopRow1++ != 0) echo "<tr>";
?>
<td><table width="145" class="repeatingtablestyle">
<tr>
<th height="120" scope="col">
///below is the concatenating string
<?php echo "<img src=".$thumbLink.$row_rsRings['thumbnails']."/>";
?>
</th>
</tr>
<tr>
<td><?php echo $row_rsRings['product name']; ?></td>
</tr>
<tr>
<td><?php echo $row_rsRings['price']; ?></td>
</tr>
<tr>
<td><?php echo $row_rsRings['item code']; ?></td>
</tr>
</table></td>

davidj
08-29-2008, 11:49 PM
$thumbLink = "root folder/images/thumbnails/";

you are not ready to learn a programming language

this is a basic level of understanding and you should realise that the path is invalid

you really need to do a basic course to familiarise your self with directory structures. Until you understand the basics you wont be able to program

confucious
09-02-2008, 03:55 PM
Hi David -

I am aware it is not a valid path by itself...it was a variable that was then inserted into a concatanated string as discussed earlier. I had removed the first two periods and / as the root path of an image inserted regularly from the same folder omitted them as well as seen below:


<p><img src="root folder/images/thumbnails/ring.jpg" width="110" height="100" /></p>

Then what I was left with was the variable:

$thumbLink = "root folder/images/thumbnails/";

and the string it was inserted into:

<?php echo "<img src=".$thumbLink.$row_rsRings['thumbnails']."/>";
?>

Anyway I do it, it does not show properly. I have tried a vast number of root paths. IN the end I stored the first path in its entirety in my MYSQL database. This seems to work well, though is not ideal.

AS to programming - I am well aware I am completely out of my depth...unfortunately I promised a family member I would help them with something, so until I am done I will have to continue along.

THanks for all your help!

davidj
09-02-2008, 06:43 PM
this is an invalid path


$thumbLink = "root folder/images/thumbnails/";


you should not have spaces in paths