CodingA database for my data

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS      
35356.141 In reply to 35356.130 
(Re-using an existing eighteen month old thread makes it more difficult to jump back to the start, and has no benefit when you're asking an entirely different question.)


Anyway, if you want to convert commas to image tags, then you can do it like this:

PHP code:
$string = '<img src="' . replace( ',' , '" /><img src="' , $string ) . '" />';


or like this:

PHP code:
$string = preg_replace( '(?:^|,)([^,]+)' , '<img src="$1" />' , $string );


(That one having the benefit of only needing to specifying the surrounding code once, although it may confuse people that don't understand regex.)


However, in most cases I'd probably do something similar to what Lucy posted (split and then foreach), because it makes things more flexible.
Any problems you're having there are most likely examples of why tables are not the right way to do layouts. :P
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Matt     
35356.142 In reply to 35356.138 
Don't suppose that code was in some way responsible for code formatting?
0/0
 Reply   Quote More 

 From:  ANT_THOMAS   
 To:  Peter (BOUGHTONP)     
35356.143 In reply to 35356.141 

1. I will start a new thread next time I want coding help :C
2. I really need to learn how to use regex stuff.
3. Nothing wrong with tables (maybe). But I doubt they're the issue here.

0/0
 Reply   Quote More 

 From:  ANT_THOMAS   
 To:  Drew (X3N0PH0N)     
35356.144 In reply to 35356.140 
There you go..
PHP code:
<?php
mysql_connect("localhost","user","pass");
mysql_select_db("cogs");

$car = $_GET['car'];

$query  = "SELECT * FROM cars WHERE carcode = '$car' ";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

$blah = split(",", $row[images]);
foreach ($blah as $beep) {
$stringading .= "<img src=\"" . $beep . "\" />";
}

echo "

<table>
    <tr>
    <th rowspan='5'><a href='#'><img src='./photos/{$row[thumb]}' /></a>
    <br />
    " . $stringading . "
    <br />
    <td colspan='2' width='300px'><a href='car.php?car={$row[carcode]}'>{$row[title]}</a></td>
    </tr>
    <tr>
    <td width='250px'>Year - {$row[year]}<br />
                      Mileage - {$row[mileage]}<br />
                      Engine - {$row[engine]}<br />
                      Fuel - {$row[fuel]}<br />
                      Gearbox - {$row[gearbox]}<br />     </td>
    <td width='250px'>Body/Doors - <br />
                      Colour - {$row[colour]}<br />
                      MOT - {$row[mot]}<br />
                      Tax - {$row[tax]}<br /></td>
    </tr>
    <tr>
    <td colspan='2'>{$row[extra]}</td>
    </tr>
    <tr>
    <td colspan='2' align='right' valign='bottom'><b>&pound;{$row[price]}</b></td>
    </tr>
    <tr>
    <td colspan='2'>FULL WIDTH</td>
    </tr>
</table>

         ";
?>
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS      
35356.145 In reply to 35356.143 
Everyone really needs to learn regex, though it seems to be eternally relegated to people's todo list. :(

Anyway, looking at the latest posted code, problem is that the while loop doesn't have a brace block - when it was a single statement (echo) it worked, but now it's multiple statements you need to group them.

PHP code:
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$blah = split(",", $row[images]);
foreach ($blah as $beep)
{
$stringading .= "<img src=\"" . $beep . "\" />";
}

echo "
...
";
}
?>
0/0
 Reply   Quote More 

 From:  ANT_THOMAS   
 To:  Peter (BOUGHTONP)     
35356.146 In reply to 35356.145 

I agree on the regex front. It seems to have been the fix for loads of stuff I've asked on here.

 

Also (hug) the extra braces worked!

0/0
 Reply   Quote More 

 From:  Matt  
 To:  Peter (BOUGHTONP)     
35356.147 In reply to 35356.142 
It is responsible for adding paragraph tags but obeying valid HTML nesting and tag ordering.

doohicky

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Matt     
35356.148 In reply to 35356.147 
Hmm, well must be something else that is stopping PHP being all coloured and stuff then?

In my previous post, there's extra line-breaks there, but in Ant's there aren't any. Might also be related in some way?
0/0
 Reply   Quote More 

 From:  ANT_THOMAS   
 To:  Peter (BOUGHTONP)     
35356.149 In reply to 35356.148 
I disabled them because they were being added extra within the code tags. If I hadn't it would've looked like yours.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS      
35356.150 In reply to 35356.149 

Ah, thought you might have done. However, it shouldn't be necessary - the line breaks shouldn't get added at all - content between code isn't supposed to be changed (excluding font/colour formatting).

 

Dunno what the cause is though - I did go look at the code Matt referred to and it's far too much effort trying to decipher it all, especially as tired as I currently am.

0/0
 Reply   Quote More 

 From:  Ken (SHIELDSIT)  
 To:  Peter (BOUGHTONP)     
35356.151 In reply to 35356.141 
Drew needs to change his nick. Lucy is a girls name.


0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Ken (SHIELDSIT)     
35356.152 In reply to 35356.151 
What's wrong with girls names, Gemma?
0/0
 Reply   Quote More 

 From:  af (CAER)  
 To:  ALL
35356.153 
Personally I'd dump the list of image filenames to a JS array and build the HTML client-side with Mustache, but that's me, I love client-side templating.
0/0
 Reply   Quote More 

 From:  ANT_THOMAS   
 To:  ALL
35356.154 
Yay I'm rubbish :C Some code
PHP code:
$sold1 = $row[sold];
if ($sold1 == yes){
$soldstring .= "<img alt=\"sold\" src=\"./photos/{$row[thumb]}\" />"; }
else {
$soldstring .= "<img alt=\"notsold\" src=\"./photos/{$row[thumb]}\" />"; }
echoing
PHP code:
" . $soldstring . "
This does as expected for the first result from the DB. But the next result contains the first image as well, and the next one the previous and so on.

So the top result shows correctly, but each result after has extra images, meaning on the 10th result it shows the correct image plus the 9 previous.

Why? :(
0/0
 Reply   Quote More 

 From:  Drew (X3N0PH0N)  
 To:  ANT_THOMAS      
35356.155 In reply to 35356.154 
.= adds to a string, = sets a string. You want = in this case. i.e.:

code:

$sold1 = $row[sold];
if ($sold1 == yes){
$soldstring = "<img alt=\"sold\" src=\"./photos/{$row[thumb]}\" />"; }
else {
$soldstring = "<img alt=\"notsold\" src=\"./photos/{$row[thumb]}\" />"; }
0/0
 Reply   Quote More 

 From:  ANT_THOMAS   
 To:  Drew (X3N0PH0N)     
35356.156 In reply to 35356.155 
(hug)
0/0
 Reply   Quote More 

 From:  Ken (SHIELDSIT)  
 To:  Peter (BOUGHTONP)     
35356.157 In reply to 35356.152 
Nothing at all except he's not a girl like you!


0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Ken (SHIELDSIT)     
35356.158 In reply to 35356.157 
Then who is he a girl like?
0/0
 Reply   Quote More 

Reply to All    
 

1–20  …  101–120  121–140  141–158

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats