1
fo-fo
displaying sql query results
  • 2005/4/21 16:04

  • fo-fo

  • Just popping in

  • Posts: 34

  • Since: 2005/4/13


in a block... how can I do that?

I would need to display a value associated with the logged-in user, yet the query username is different. so the second question is where to put the <{$xoops_uname}> tag to get relevant results?

thanks.

I guess this script queries the database

<?php
//connect to server with username and password
$connection = mysql_connect ("localhost","username", "password") or die ("Cannot make the connection");
//connect to database
$db = mysql_select_db ("test",$connection) or die ("Cannot connect to database");
//our SQL query
$sql_query = "SELECT * FROM test LIMIT 1";
//store the SQL query in the result variable
$result = mysql_query($sql_query);
if(mysql_num_rows($result))
{
//output as long as there are still available fields
while($row = mysql_fetch_row($result))
{
echo ("<a href=\"$row[2]\">$row[3]</a>");
echo (": $row[4]<br>");
}
}
//if no fields exist
else
{
echo "no values in the database";
}

?>

2
fo-fo
Re: displaying sql query results
  • 2005/4/21 22:00

  • fo-fo

  • Just popping in

  • Posts: 34

  • Since: 2005/4/13


my syntax is wrong or is this some kinda impossible thing.

I couldn't get results with it.

the edited block template looks like this -

<table cellspacing="1" class="outer">
<{foreach item=user from=$block.users}>
<tr class="<{cycle values="even,odd"}>" valign="middle">
<td align="center">
<a href="<{$xoops_url}>/user.php"><{$xoops_uname}></a>
</td>
<td align="center">
<?
mysql_connect("localhost", name, password);
$result = mysql(mydatabase, "SELECT quan FROM points WHERE
players.id=points.player_id AND <{$xoops_uname}>=players.first_name");
echo $result;
?>
</td>
</tr>
<{/foreach}>
</table>



the sql tables look like this -

players:
first_name...id
xxx..........1

points:
player_id....quan
1............100

so the result shoud be 100
where is the flaw?

Login

Who's Online

229 user(s) are online (156 user(s) are browsing Support Forums)


Members: 0


Guests: 229


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Jun 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits