Forum Moderators: coopster

Message Too Old, No Replies

New to site and PHP coding

         

tjcares

12:26 pm on Nov 13, 2009 (gmt 0)

10+ Year Member



Hello all!
New to the forum and to PHP coding and have hit a wall while trying to cod something.

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

andrewsmd

4:48 pm on Nov 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two things I would try. First echo your query and run it manually in a mysql shell to make sure it is a valid query
i.e.
$result = mysql_query('SELECT COUNT(DISTINCT(credit_members_id)) as count FROM vtp_tracking
WHERE action_date > date_sub(NOW(),interval 1 minute)');
echo($result);
Copy and paste that into a mysql shell. If it works then I would also add this

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.

rocknbil

8:01 pm on Nov 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard tjcares!

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;