Hello I want to echo an img with a href in php but i am having problem, anyone that can help me with the problem ? :/ echo '<a href="mypage.com/index.php?dog=' . $id . '" target="_blank"><img src="/thumb/' . $id . '.jpg /></a>';
Well you forgot a double quote in the src attribute. Don't see anything else so far, but then again I'm not even sure what your problem is...
I am getting Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' on whatever i attept when using it :/
Does this work? echo '<a href="mypage.com/index.php?dog=' . $id . '" target="_blank"><img src="/thumb/' . $id . '.jpg" /></a>'; Are you sure $id contains a number?
That line doesn't have any syntax errors (at least not PHP's syntax). Can you post some more code? Perhaps a few lines above, and a few lines below?
Thank you that worked like a charm!!! i have this in a loop now like the code bellow and i was wondering, can i do a pagenation somehow in this loopt? i have almost 1000 entries in my database and i just limit it to 5 for testing right now but would like tho pagenate it all if i remove the "limit" so to say :/ <?php $getquery=mysql_query("SELECT * FROM dogs ORDER by ID LIMIT 5"); while($rows=mysql_fetch_assoc($getquery)) { $id=$rows['id']; echo'br'; echo 'mypage.com/index.php?dog=' . $id . '" target="_blank"><img src="/thumb/' . $id . '.jpg" /></a>'; echo ''; } ?> PHP: [/quote]
<?php $page = (int)$_GET['page']; $perpage = 5; if ($page<1) $page = 0; $getquery=mysql_query("SELECT * FROM dogs ORDER by ID LIMIT ".($perpage*$page).",".$perpage); while($rows=mysql_fetch_assoc($getquery)) { $id=$rows['id']; echo'br'; echo 'mypage.com/index.php?dog=' . $id . '" target="_blank"><img src="/thumb/' . $id . '.jpg" /></a>'; echo ''; } $getquery=mysql_query("SELECT count(*) FROM dogs ORDER by ID"); $total = mysql_result($getquery,0); echo "<div class='paging'>"; for ( $n = 0; $n <= $total; $n++ ) { echo "<a href=\"?page=".$n."\">".$n."</a>"; } echo "</div>"; ?> Code (markup): something like this... havn't test it, jsut coded. ask questions if you need more help
Hey Gansta and thanks for looking at it, it tried running the code and get it to work but it just ends up like this along with the error "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource" https://www.dropbox.com/s/yi9dmbzq7isqrvv/pagen.png
Some extra advice: First up, STOP using string addition on ECHO when you don't have to. It's a hair slower and uses more memory since it has to be built and sent. Try this test to see what I mean. It'll leave you scratching your head until you figure out the difference. <?php function testWorld() { echo 'world ' }; echo 'hello ',testWorld(), '<br />'; echo 'hello ' . testWorld() . '<br />'; ?> Code (markup): The output from that ends up: hello world world hello String addition is run before being sent to echo, comma delimits are sent separately one at a time. Splitting the formatting to multiple lines helps too in making it easier to check for errors, and of course this is 2013 not 1998, it's unlikely you're inside a frameset, so why are you using TARGET? echo ' <a href="mypage.com/index.php?dog=', $id, '"> <img src="/thumb/', $id, '.jpg" alt="DESCRIBE THIS!" /> </a>'; Code (markup):
in your original post you never added the last double quotes after .jpg therefore your HTML tag was never. and ran straight through with code picking up characters and assuming a unexpected string or ',' etc. and monkeyeye accidently forgot them after dog= which by both accidental oversights is having you looking for ghost gremlins that never existed. you must close the double quotes...and add them everywhere they belong without becoming confused when single quotes end the echo line when ever double and single quotes end up in stack "'"'''''""" etc or when they start stop to fit $vars in is always where things sometimes go wrong. Try this one: echo '<a href="mypage.com/index.php?dog="' . $id . '" target="_blank"><img src="/thumb/' . $id . '.jpg"></a>';