Click to See Complete Forum and Search --> : Change Variabel OnClick


PJStew
01-22-2007, 08:32 AM
Hi all,

Is it posible to change a variable OnClick using a text link instead of a form?

e.g.

<?php
function trials()
{
$style = "trials";
}
echo "<a onclick=\"trials()\" >Trials</a>";

// instead of

echo "<input type=\"button\" onclick=\"trials()\">";
?>


The reason i want to do this is because on my site i have a view 9 page for view picture of diferant style, e.g. trials, steet, freestyle.... the pages are the same except the style of picture the code selects from the database. e.g.
$sql2 = "SELECT COUNT(*) as `count` FROM uploaded_images WHERE style = 'trials' ORDER BY `date` ASC";
if i change "trials" to the variable "$style" and then make it so $style can be changed to street, freestyle or any of the other style, then i would only need one page instead of 9... ;)

all the 9 pages link to eachother on the left of the page here's a link (http://www.unicyclepics.co.uk/display.trials2.php) to one of the pages as it is now.

I would rather not use Javascript if pos.

thanks in advace. :)

NightShift58
01-22-2007, 03:28 PM
I don't think so because anything after "onclick=" refers to javascript and you cannot referencea PHP function that way.

PJStew
01-23-2007, 12:58 PM
I don't think so because anything after "onclick=" refers to javascript and you cannot referencea PHP function that way.


ok, can anyone suggest a way this could be done? idealy using PHP :confused:

NightShift58
01-23-2007, 01:13 PM
How about this?

display.all.php:
<?php
echo "<a href='display.styles.php?style=trials'>Trials</a>";
echo "<a href='display.styles.php?style=street'>Street</a>";
echo "<a href='display.styles.php?style=muni'>Muni</a>";
echo "<a href='display.styles.php?style=freestyle'>Freestyle</a>";
// etc...
?>
display.styles.php:
<?php
//Db connect here
$QUERYstyle = isset($_GET['style']) ? $_GET['style'] : "all";

$sql2 = "SELECT * FROM uploaded_images ";
IF ($QUERYstyle <> "all") :
$sql2 .= "WHERE `style` = 'trials' ";
ENDIF;
$sql2 .= "ORDER BY `date` ASC";

$qry2 = mysql_query($sql2) or die("SQL Error: $sql2<br>" . mysql_error());

$QUERYcount = mysql_num_rows($qeyr2);

WHILE ($row = mysql_fetch_array($qry2)) :
// display?
ENDWHILE;
?>

PJStew
01-23-2007, 02:15 PM
How about this?

display.all.php:
<?php
echo "<a href='display.styles.php?style=trials'>Trials</a>";
echo "<a href='display.styles.php?style=street'>Street</a>";
echo "<a href='display.styles.php?style=muni'>Muni</a>";
echo "<a href='display.styles.php?style=freestyle'>Freestyle</a>";
// etc...
?>
display.styles.php:
<?php
//Db connect here
$QUERYstyle = isset($_GET['style']) ? $_GET['style'] : "all";

$sql2 = "SELECT * FROM uploaded_images ";
IF ($QUERYstyle <> "all") :
$sql2 .= "WHERE `style` = 'trials' ";
ENDIF;
$sql2 .= "ORDER BY `date` ASC";

$qry2 = mysql_query($sql2) or die("SQL Error: $sql2<br>" . mysql_error());

$QUERYcount = mysql_num_rows($qeyr2);

WHILE ($row = mysql_fetch_array($qry2)) :
// display?
ENDWHILE;
?>

Thanks NightShift!!! I didn't use the exact code, but you pointed me in the right direction. ;) I'll have the new page up soon, and will put a link on this thread if you would like to see it working... :)

Thanks again! ;)

NightShift58
01-23-2007, 02:22 PM
You're welcome! And, yes, it'd be nice to see the final product. On a forum, you often end up working in a sort of vacuum and never really see what happens to the stuff...