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?
href with select
Moderator: General Moderators
- greenhorn666
- Forum Commoner
- Posts: 87
- Joined: Thu Aug 14, 2003 7:14 am
- Location: Brussels, Belgium
confused
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:
Or did I get you totally wrong?
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
}- greenhorn666
- Forum Commoner
- Posts: 87
- Joined: Thu Aug 14, 2003 7:14 am
- Location: Brussels, Belgium
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:
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
And in your page in the table:
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...
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>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
<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, '1 is user admin<br>2 is user noob<br>');
}
-->
</script>Code: Select all
<table>
<tr>
<td name="details"><a href="#" onClick="displayDetails()">Show details</a><br />
</td>
</tr>
</table>I would go for the argument solution...