Page 1 of 1

href with select

Posted: Mon Aug 18, 2003 9:21 am
by pachox
my code is like this:

<tr onMouseOver="this.className='GridMOverRow'" onMouseOut="this.className='GridRow'"class="GridRow"><a href="#"><?php
$db_name = "DBMedici";
$table_name = "articoli";
$connect = @mysql_connect("localhost", "root", "") or die("connect che????");
$select_db = @mysql_select_db($db_name, $connect) or die("cannot select db");

$sql = "
select id, titolo, testo, argomenti from $table_name order by argomenti
";

$result = @mysql_query($sql, $connect) or die("non riesco a fare query");

while ($riga = mysql_fetch_array($result)) {

$riga['titolo'];
$riga['articoli'];

}
?>
<?php echo $titolo; ?></a></tr>


i'd like to do the select on click and so print results in the page

how should i do?

confused

Posted: Mon Aug 18, 2003 10:02 am
by greenhorn666
Hi,
I'm not sure if I am confused (by your question) or you are (by server-side scripting)...
What exactly are you trying to do here?
- some javascript that will display the result of the query above?
- or redirect to some page that will display the result of the query?

Because if you are trying the js thing, then you have to understand this:
php is a server-side scripting language, meaning that the scripting will be processed before the answer is being sent to the client (the user's browser).
So if you want to display the result upon click (à la onClick=) you have to add a JS function that will append data to the cell.
That data being fixed in the page and processed upon page request by PHP.

In the second case, your scripting has nothing to do there, but should be in the page that you would like to display the result (or pass an argument to the page, telling that the user wishes to get the info, like:
page.html?viewDetails=true for instance, where in your page you would have a condition statement for:

Code: Select all

if(isset($_GET["viewDetails"] 
        && $_GET["viewDetails"] == "true") {
    // Do query and display result here
}
Or did I get you totally wrong?

Posted: Mon Aug 18, 2003 10:43 am
by pachox
well, say i'm looking for a js to do that
what should i write?

Posted: Mon Aug 18, 2003 11:02 am
by greenhorn666
Heh!

Well since I'm no good at JS you should probably look some stuff up on the http://www...
But you should have something like:

Code: Select all

<script language="javascript">
<!--
function displayDetails() {
   // find ou how to alter the td named "details" here
   // I'll assume you code the function modify(name, newValue)

    modify(details, '<?
// Here comes the PHP code outputing the details
// Like:
$result = mysql_query("SELECT * FROM table");
//
while(list($id, $name) = mysql_fetch_array($result))
    echo "$id is user $name<br />";
mysql_free_result($result);
?>');
}
-->
</script>
Well this is all real messy, but should give you an idea (I won't go into MVC right now ;))
See? what's colored is php (interpreted on server-side) and black is JS and/or HTML (server-side)

So in your browser you would have

Code: Select all

&lt;script language="javascript"&gt;
&lt;!--
function displayDetails() &#123;
   // find ou how to alter the td named "details" here
   // I'll assume you code the function modify(name, newValue)

    modify(details, '1 is user admin&lt;br&gt;2 is user noob&lt;br&gt;');
&#125;
--&gt;
&lt;/script&gt;
And in your page in the table:

Code: Select all

&lt;table&gt;
&lt;tr&gt;
&lt;td name="details"&gt;&lt;a href="#" onClick="displayDetails()"&gt;Show details&lt;/a&gt;&lt;br /&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
Hope this helps a bit, but again, I'm bad at JS... You could possibly get JS to query some page on your server to get the "details" in real-time... But I have no clue about this in JS.
I would go for the argument solution...