Page 1 of 1

clike of diffrent places = same result. how to do it???!!

Posted: Sat Dec 05, 2009 2:31 pm
by vin_akleh
why this doesn't work!!!??

Code: Select all

<?php
    $qu=mysql_query("select * from la order by li desc limit 5");
    while ($max=mysql_fetch_array($qu))
    {
        if ($max['im']=='') 
            $max['im']='ims/default.jpg';
        echo '<td><table class=media><tr><td>
            <input type="image" name="select" value="'.$max["li"].'" src="'.$max['im'].'" width=150 height= 200/>';
        echo'</a></td></tr><tr>';
        if (strlen($max["ti"])>16)
            $mal["ti"]=substr($max["ti"],0,16).'...';
    echo '<td><input type="submit" name="select" value="'.$max["ti"].'" class="trans2"></td></tr></table></td>';
    }//end while
?>
 
result after click on image or string

Code: Select all

//$qu=mysql_query("select * from la where li like '".$select."'");
    $qu=mysql_query("select * from la where ti like '".$select."'");    
    while ($max=mysql_fetch_array($qu))
    {
        if ($max['im']=='') 
        $max['im']='ims/default.jpg';
        echo '<table class=select><tr><td>
        <img src="'.$max['im'].'" width=300 height=400/>';
        echo'</a></td></tr><tr>';
        echo '<td>'.$max["ti"].'</td></tr></table>';
    }//end while
echo'<tr><td>'.$qu['im'].'</tr><td>';
the problem is here
$qu=mysql_query("select * from la where li like '".$select."'");
$qu=mysql_query("select * from la where ti like '".$select."'");
one of them will work but not both
i want both of them to work, if the user clicks on the image or the ti (string) the same result will come up for the user. i have tried if condition and other thing nothing worked either the image or the string not both.(i know that in this code i show here, has "//" before $qu)
thanks in advanced :D

Re: clike of diffrent places = same result. how to do it???!!

Posted: Wed Dec 09, 2009 2:42 pm
by vin_akleh
still need help
anyone????????????!!!!!!!!!!!!

Re: clike of diffrent places = same result. how to do it???!!

Posted: Wed Dec 09, 2009 3:00 pm
by AbraCadaver
vin_akleh wrote:still need help
anyone????????????!!!!!!!!!!!!
I don't totally understand, but what I can tell you is:

Code: Select all

'<input type="im" name="select" value="'.$max["li"].'" src="'.$max['im'].'" width=150 height= 200/>'
#1 there is no input type="im":
#2 if you meant type="image" then it does not pass the value, it passes the x, y coordinates of where the image was clicked

You might try:

Code: Select all

'<input type="image" src="'.$max['im'].'" width=150 height= 200/>
<input type="hidden" name="select" value="'.$max["li"].'">'

Re: clike of diffrent places = same result. how to do it???!!

Posted: Wed Dec 09, 2009 3:04 pm
by vin_akleh
image yes thanks
but how can i pass a value using an image
i mean it has already worked for me but not both of them at the same time!

Re: clike of diffrent places = same result. how to do it???!!

Posted: Wed Dec 09, 2009 3:36 pm
by AbraCadaver
Several ways to do it. Here is how I would as an example (assuming you're using POST):

Code: Select all

'<input type="image" src="'.$max['im'].'" width="150" height="200">'
'<input type="hidden" name="li" value="'.$max["li"].'">'
 //etc...
'<input type="submit" name="ti" value="'.$max["ti"].'" class="trans2">'
Now, the hidden value $_POST['li'] is always set, but $_POST['ti'] is only set if you click the Submit button. So we check for $_POST['ti'] and if set use it and if not we use $_POST['li']:

Code: Select all

if(isset($_POST['ti'])) {
    $like = $_POST['ti'];
} else {
    $like = $_POST['li'];
}
$qu = mysql_query("SELECT * FROM `la` WHERE `ti` LIKE '" . mysql_real_escape_string($like) . "'");
Make sense?

Re: clike of diffrent places = same result. how to do it???!!

Posted: Wed Dec 09, 2009 3:48 pm
by vin_akleh
ya thanks ill try it

Re: clike of diffrent places = same result. how to do it???!!

Posted: Thu Dec 10, 2009 10:01 am
by vin_akleh
you mean like this

Code: Select all

$qu = mysql_query("SELECT * FROM `li` WHERE '" . mysql_real_escape_string($like) . "' LIKE '".$select."'");
this doesn't work, half of the page doesn't load

did you see that i have the same name for the "image" and the "submit" type?? is that a problem?

Re: clike of diffrent places = same result. how to do it???!!

Posted: Thu Dec 10, 2009 10:21 am
by AbraCadaver
vin_akleh wrote:you mean like this

Code: Select all

$qu = mysql_query("SELECT * FROM `li` WHERE '" . mysql_real_escape_string($like) . "' LIKE '".$select."'");
this doesn't work, half of the page doesn't load

did you see that i have the same name for the "image" and the "submit" type?? is that a problem?
You can only click the submit button OR the image, not both, so you will have only 1 value. I fail to see what you are trying to do.

Re: clike of diffrent places = same result. how to do it???!!

Posted: Thu Dec 10, 2009 10:35 am
by vin_akleh
yes that is what i want, one of them clicked either the image or the submit, the user will click on what he prefers not both ant the same time.

Re: clike of diffrent places = same result. how to do it???!!

Posted: Thu Dec 10, 2009 11:51 am
by AbraCadaver
I spotted my mistake. Maybe this will work, but you'll have to use the names of the inputs the way I showed in my last post.

Code: Select all

if(isset($_POST['ti'])) {
    $like = $_POST['ti'];
    $field = 'ti';
} else {
    $like = $_POST['li'];
    $field = 'li';
}
$qu = mysql_query("SELECT * FROM `la` WHERE `$field` LIKE '" . mysql_real_escape_string($like) . "'");