Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Formating results back from mysql
Old 06-24-2004, 06:31 PM Formating results back from mysql
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
How would I go about placing pictures after getting information back from the database?

For example.

I recall the Username and Email of each member. Which is placed in a table.
Then I recall their security level. And if their security level is "1" then display "1.gif" after their username and email.

Then it goes to the next entry but their security level is "2", so it now places 2.gif behind that users name and email.


Any help would be greatly appreciated.
Thanks,
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-24-2004, 06:43 PM
Unknown.

Posts: 1,693
Trades: 0
This should do....

PHP Code:
<?php

function check($Security_level) { 
    if( 
$Security_level )  return '1.gif'
    if( 
$Security_level )  return '2.gif'


$User_level check($Security_level);

echo 
"$User_level";

?>
Hope this helps

If you need any more help just ask

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 06-24-2004, 06:43 PM
Junior Talker

Posts: 3
Trades: 0
Edit: You beat me to it!

PHP Code:
<?php
$level 
= ($security_level == "2") ? "2.gif" "1.gif";
echo 
"<img src='$level'>";
?>
Strike Hosting is offline
Reply With Quote
View Public Profile Visit Strike Hosting's homepage!
 
Old 06-24-2004, 08:15 PM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Thanks for the quick responses
I'll give it a go and let you guys know whats up


Cher,
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 06-24-2004, 09:17 PM I dunno..
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
I think I stuffed up somewhere lol. It returned text "1.gif"
Here is my php code in total.
PHP Code:
<? 
/* declare your DB variables */ 
$DBname 'lothop_'
$DBuser '*****'
$DBpass '*****'
$DBhost 'localhost'

/* Make The Connection */ 
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable toconnect to database"); 
@
mysql_select_db("lothop_") or die("Unable to select database $DBName"); 

/* SQL */ 
$sqlquery "SELECT email,username FROM users"
$result   mysql_query($sqlquery); 
$number   mysql_num_rows($result); 

/* Display Results */ 
if($number 1
    print 
"<CENTER><P>There Were No Results for Your Search</CENTER>"
else 

    while(
$data mysql_fetch_array($result)) 
    { 
        
$name $data['email']; 
        
$age  $data['username']; 
        print 
"<p><b>Name:</b> $name<br><b>Age:</b> $age</p>";  
    } 


function 
check($level_id) { 
    if( 
$level_id )  return '1.gif'
    if( 
$level_id 10 )  return '2.gif'


$User_level check($level_id); 

echo 
"$User_level"


?>
Their Security levels are stored in the database as level_id in the table users.

Any help on this would be leg-end

Thanks,
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 06-24-2004, 10:50 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
lothop,

If you want to see the image, you need to put the text (which is the name of the image file) into an image tag.


PHP Code:
<?php
    $userLevelImg 
check($level_id);
?>
<img src="yourImagesPath/<?= $userLevelImg ?>" />
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 06-26-2004, 07:22 AM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
I can't seem to get this to work.
I need it to be able to,

Display their username, display their email, then display their security picture.

I tried those codes, but I couldn't implement

PHP Code:
<?php 
    $userLevelImg 
check($level_id); 
?> 
<img src="yourImagesPath/<?= $userLevelImg ?>" />
I get error "Fatal error: Call to undefined function: check() in /home/lothop/public_html/testing/memberstest.php on line 126"

And those other codes just seem to always display the same picture.

Is it possible to, check to see what $level_id they are off the database, then if their $level_id is 1, display 1.gif, if $level_id is 2, display 2.gif.

And somehow incorperate it into it displaying the username and email and the picture.

Thanks
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 06-28-2004, 04:42 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
lothop,

Ok, based on your previous post, you indicated that check() was just returning "1.gif" and now you are getting an error when you call check()? Are you including the file in which check() is defined?
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 06-28-2004, 05:35 PM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
I don't know which code im suppost to be using.

Do I use
PHP Code:
<?php 

function check($Security_level) { 
    if( 
$Security_level )  return '1.gif'
    if( 
$Security_level )  return '2.gif'


$User_level check($Security_level); 

echo 
"$User_level"

?>
And then within that code add
PHP Code:
<?php 
    $userLevelImg 
check($level_id); 
?> 
<img src="yourImagesPath/<?= $userLevelImg ?>" />
I'm kinda confused
hehe

Thanks
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 06-28-2004, 05:49 PM
Unknown.

Posts: 1,693
Trades: 0
First you have...

PHP Code:
<?php 

function check($Security_level) { 
    if( 
$Security_level )  return '1.gif'
    if( 
$Security_level )  return '2.gif'


$User_level check($Security_level); 

echo 
"$User_level"

?>
Then add...

PHP Code:
<img src="yourImagesPath/<?= $userLevelImg ?>" />
into the Html where you want the image to appear

Hope this helps

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 06-29-2004, 02:23 AM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
It's still not working.
It displays 1.gif, and then tries to display a picture that it cant find, eventhough the image is right there.

Example http://www.lothop.clanecko.net/testing/memberstest.php


My code is
PHP Code:
<?
function check($level_id) { 
    if( 
$level_id )  return '1.gif'
    if( 
$level_id 10 )  return '2.gif'


$User_level check($level_id); 

echo 
"$User_level";


?>
              <img src="<?= $userLevelImg ?>" />
But above that is the database connection code. So it is connected to the database.

Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 06-29-2004, 02:49 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
At this point, I would recommend you take a close look at the resulting HTML in your browser. Check the path to your image, etc. Do you see any errors there?
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 06-29-2004, 05:22 AM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
The images path is fine. As far as I know its just php code thats stuffing up.

Just wondering, if it was working but couldnt find the image their would be an image for each user that couldn't be found.

Why would it be displaying 1.gif?
Is the php code displaying an image for each member?

Umm, one question though, do I need to store the images in the database or just have the files on the server?

Other than those possible errors I can't see any others..
Thanks,
Lothop

Last edited by lothop; 06-29-2004 at 05:27 AM..
lothop is offline
Reply With Quote
View Public Profile
 
Old 06-29-2004, 07:44 AM
Unknown.

Posts: 1,693
Trades: 0
Quote:
Originally Posted by lothop
Umm, one question though, do I need to store the images in the database or just have the files on the server?
You store the pics on your server...

So the pics should be @

http://www.lothop.clanecko.net/testing/1.gif
http://www.lothop.clanecko.net/testing/2.gif

Hope this helps

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 06-29-2004, 06:34 PM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Ok, well they are stored on the server.. I still can't get this to work >.<

Thanks for your continueing help
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 06-29-2004, 07:30 PM
Unknown.

Posts: 1,693
Trades: 0
Got an example of the coding for the whole page??

Might be able to find whats wrong

Also one thing.. On your Site I wouldn't display the email addresses of the members.. Otherwise they will recieve loads of spam.. You could always put 'you [at] yoursite.com'

-James

Last edited by Dark-Skys99; 06-29-2004 at 07:32 PM..
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 06-29-2004, 11:52 PM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
It was a test page I'm not going to be displaying the members emails in the final run.


<html>
<head>
<title>Madox Guild - Members</title>
<meta name="description" content="A Gunbound Guild with it all! Join the Madox Guild today!">
<meta name="keywords" content="Gunbound Madox ">
<META NAME="keyphrases" CONTENT="Best gunbound guild, Gunbound tips and tricks">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="forAll.css" rel="stylesheet" type="text/css">
</head>
<body background="images/bg.gif" link="#003399" vlink="#0044D2" alink="#FF3300" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div align="center">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="83" background="images/top_bg.gif"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr valign="top">
<td width="50%"><a href="index.php"><img src="images/logo.gif" width="188" height="83" border="0"></a></td>
<td width="50%" align="right"><img src="images/statement.gif" width="202" height="25"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="22" background="images/menu_bg.gif" class="forTexts"><div align="right">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="293">&nbsp;</td>

<td width="707" class="forTexts">|&nbsp;&nbsp;&nbsp;&nbsp;<a href="about.html">About
the Guild</a>&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.lothop.clanecko.net/forum/index.php" target="_blank">Forum</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp ;&nbsp;
<a href="sitemap.html">Sitemap</a>&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;
<a href="contact.html">Contact</a>&nbsp;&nbsp;&nbsp;&nbsp; | </td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td valign="top"><table class="forTexts" width="1000" border="0" cellpadding="2" cellspacing="0">
<tr>
<td width="168" valign="top"> <table width="100%" border="0" cellpadding="1" cellspacing="1">
<tr>
<td bgcolor="#4F7DB0" class="forTexts">&nbsp;</td>
<td bgcolor="#D9E3EE" class="forTexts">&nbsp;<a href="index.php">Home</a></td>
</tr>
<tr>
<td bgcolor="#4F7DB0" class="forTexts">&nbsp;</td>
<td bgcolor="#D9E3EE" class="forTexts">&nbsp;<a href="rules.html">Rules</a></td>
</tr>
<tr>
<td bgcolor="#4F7DB0" class="forTexts">&nbsp;</td>
<td bgcolor="#D9E3EE" class="forTexts">&nbsp;<a href="members.php">Members</a></td>
</tr>
<tr>
<td bgcolor="#4F7DB0" class="forTexts">&nbsp;</td>
<td bgcolor="#D9E3EE" class="forTexts">&nbsp;<a href="restricted/index.php">Login</a></td>
</tr>
<tr>
<td bgcolor="#4F7DB0" class="forTexts">&nbsp;</td>
<td bgcolor="#D9E3EE" class="forTexts">&nbsp;<a href="restricted/register1.php">Join</a></td>
</tr>
<tr>
<td bgcolor="#4F7DB0" class="forTexts">&nbsp;</td>
<td bgcolor="#D9E3EE" class="forTexts">&nbsp;<a href="javascript:window.external.AddFavorite('http ://www.madox.co.nr',
'Madox Guild')">Bookmark</a></td>
</tr>
</table>
<br> <table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td height="20" bgcolor="#80A0C6" class="forTexts"> <div align="center"><font color="#FFFFFF">&nbsp;Announcement</font></div></td>
</tr>
<tr>
<td bgcolor="#E9EFF5" class="forTexts"> <table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>

<td class="forTexts">Madox Guild is up and running. Still
working out a few glitches but should be sorted out
quickly. </td>
</tr>
</table></td>
</tr>
</table>
<br>
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td height="20" bgcolor="#80A0C6" class="forTexts"> <div align="center"><font color="#FFFFFF">&nbsp;News
&amp; Events</font></div></td>
</tr>
<tr>
<td bgcolor="#E9EFF5" class="forTexts"> <table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>

<td class="forTexts">Guild started on 25/6/04</td>
</tr>
</table></td>
</tr>
</table></td>
<td width="675" valign="top">
<?
/* declare your DB variables */
$DBname = 'lothop_';
$DBuser = '***';
$DBpass = '***';
$DBhost = 'localhost';

/* Make The Connection */
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable toconnect to database");
@mysql_select_db("lothop_") or die("Unable to select database $DBName");

/* SQL */
$sqlquery = "SELECT email,username FROM users";
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result);

/* Display Results */
if($number < 1)
print "<CENTER><P>There Were No Results for Your Search</CENTER>";
else
{
while($data = mysql_fetch_array($result))
{
$email = $data['email'];
$username = $data['username'];
print "<p><b>Username:</b> $name<br><b>Email:</b> $email</p>";
}

function check($level_id) {
if( $level_id = 1 ) return '1.gif';
if( $level_id = 10 ) return '2.gif';
}

$User_level = check($level_id);

echo "$User_level";

}
?>
<img src="<?= $userLevelImg ?>" />
<td width="150" valign="top">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td height="20" bgcolor="#80A0C6" class="forTexts"> <div align="center"><font color="#FFFFFF">&nbsp;Poll</font></div></td>
</tr>
<tr>
<td bgcolor="#E9EFF5" class="forTexts"> <table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>

<td class="forTexts"><div align="center">No poll at the
moment.</div></td>
</tr>
</table></td>
</tr>
</table>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
<tr>

<td height="40" background="images/bottom_bg.gif"> <span class="forTexts">All
Rights Reserved. 2004. www.madox.co.nr Webmaster <a href="mailto:Lothop@xtra.co.nz">Lothop</a></span></div>
</div></td>
</tr></table>
</body>
</html>

The database field is called "id_level"
Image names are "1.gif" & "2.gif"
Images location on the server is in the same folder as this page.

Thanks,
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 06-30-2004, 05:36 AM
Unknown.

Posts: 1,693
Trades: 0
Its the PHP bit thats the problem...

The code needs to be changed to...
PHP Code:
<? 
/* declare your DB variables */ 
$DBname 'lothop_'
$DBuser '***'
$DBpass '***'
$DBhost 'localhost'

/* Make The Connection */ 
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable toconnect to database"); 
@
mysql_select_db("lothop_") or die("Unable to select database $DBName"); 

/* SQL */ 
$sqlquery "SELECT email,username FROM users"
$result mysql_query($sqlquery); 
$number mysql_num_rows($result); 

/* Display Results */ 
if($number 1
print 
"<CENTER><P>There Were No Results for Your Search</CENTER>"
else 

while(
$data mysql_fetch_array($result)) 

$email $data['email']; 
$username $data['username']; 
print 
"<p><b>Username:</b> $name<br><b>Email:</b> $email</p>";


function 
check($level_id) { 
if( 
$level_id ) return '1.gif'
if( 
$level_id 10 ) return '2.gif'


$User_level check($level_id); 

?>
<img src="<?= $User_level ?>" />
The reason you were getting the 1.gif text was because you had echoed it 'echo "$User_level";'

Also you needed to change the <img src="<?= $userLevelImg ?>" /> to $User_level

The code should work now

Hope this helps

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 06-30-2004, 07:02 AM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Yay, it's now displaying a picture, but it is only displaying one picture. And it is the picture that is linked to a member whom has a level_id of 1.

How do I make it so it displays a picture for each member?

I have tried to put the code that shows the image into the loop in the php where it displays the members information, but everything I've tried is failed.

Thanks for your help,
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 07-02-2004, 01:56 AM Idea
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
I've been working through this.. and I have tried to make the code simpler.

PHP Code:
/* SQL */ 
$sqlquery "SELECT email,username,level_id FROM users"
$result mysql_query($sqlquery); 
$number mysql_num_rows($result); 

/* Display Results */ 
if($number 1
print 
"<CENTER><P>There Were No Results for Your Search</CENTER>"
else 

while(
$data mysql_fetch_array($result)) 

$username $data['username']; 
$level_id $data['level_id']; 
print 
"<p><b>Username:</b> $username<br></p>"
if( 
$level_id ==) echo '<img src="1.gif">'
if( 
$level_id ==10 ) echo '<img src="2.gif">';

Which gets the results of http://www.lothop.clanecko.net/testing/memberstest.php

It is now displaying the correct image for the level_id 1 (members with a rank of 1) but the admin gets no picture (rank of 10) Do you have any idea why? I sure don't ><

Thanks,
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Formating results back from mysql

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.63006 seconds with 12 queries