Forum Moderators: coopster
This code I made yesterday and it works fine:
<?php
include("mysql_config.php");
if ($dbc = mysql_connect ($host, $user, $passwrd)) // make connection
{
if (!mysql_select_db ($db))
{ // If it can not select the database.
echo 'failed to select db';
exit();
}
$result = mysql_query('SELECT COUNT(DISTINCT(credit_members_id)) as count FROM vtp_tracking
WHERE action_date > date_sub(NOW(),interval 1 minute)');
$row = mysql_fetch_array($result);
$now_surfing = $row['count'];
echo $now_surfing;
}
else
{
echo 'Failed to connect to mysql';
}
?>
This tells me how many people are surfing and goes on a splash page for everyone to see off site.
Now I would like to do a header for the rotator using this code.
SELECT name FROM vtp_members WHERE id={members_id}
This shows the name of the person promoting the Page
But I can't figure out how to get it to work using the script above a little help would go a long way:)
Thanks in advance for any help!
Dave
Instead of
$row = mysql_fetch_array($result);
$now_surfing = $row['count'];
echo $now_surfing;
try
$row = mysql_fetch_array($result);
while($row = mysql_fetch_assoc($result)){
$now_surfing = $row['count'];
echo $now_surfing;
}
Note that if there is more than one result it will be displayed. Let me know if that helped.
Now I would like to do a header for the rotator using this code.
Is the file name for the member's banner stored in the table? It should be, might make this easier. You don't say how you're getting "members_id" but if you can figure that out, no problem.
// define somewhere at top
$images_url = '/images/members';
$images_virtual = '/system/path/to/images/members';
// Good habit to form: put your query strings in vars.
// Put all this right after "echo $now_surfing; "
$query = "SELECT name,image_filename FROM vtp_members WHERE id=$member_id";
$result = mysql_query($query);
($row = mysql_fetch_array($result);
$username = $row['name'];
$filename = $row['image_filename'];
if (is_file("$images_virtual/$fname")) {
$user_header = '<img src="' . $image_url . '/' . $filename . '" alt="header for member ' . $username . '">';
}
else {
$user_header = '<p><strong>' . $username . ',</strong> you have not yet uploaded a header.';
$user_header .= '<a href="upload_header.php">Upload one now</a></p>';
}
echo $user_header;