Web Design Forum: MySQL Noob help :) - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

MySQL Noob help :) Rate Topic: -----

#1 User is offline   Rookie_Racer 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 51
  • Joined: 14-October 08
  • Reputation: 0
  • Experience:Intermediate
  • Area of Expertise:I'm Learning

Posted 07 August 2009 - 12:40 AM

So i have this database, for example we have the user admin with 1 refferal, so it has under the row refferals 1

we then have the user 'test' who has 0 refferals but in the refferer row it has admin,


what i need is a way to fetch the data from the db, i dont know how tho you see ima n00000b :)

here is my mysql.phpb

Quote

<?
include"config.php";
//db connection

$database="gpt"; //your database name
$dbuser="root"; //admin user of the database
$dbpass=""; //password of the admin user of the database - no passs for root

$c=mysql_connect ('localhost',$dbuser,$dbpass) or die(mysql_error());
mysql_select_db ($database,$c) or print(mysql_error());

?>



i currently have this, which i guess is wrong

<?php
include 'mysql.php';

$query  = "SELECT refferals, subject, FROM gpt";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo "refs :{$row['refferals']} <br>"       
}

?>



thanks
0

#2 User is offline   Thomas Thomassen 

  • HTTP 503
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,254
  • Joined: 30-April 07
  • Reputation: 10
  • Gender:Male
  • Location:Trondheim, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 07 August 2009 - 06:24 AM

Looks ok. What's wrong? Error messages or no output? Have you tried to output the whole $row array to investigate it?

0

#3 User is offline   Rookie_Racer 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 51
  • Joined: 14-October 08
  • Reputation: 0
  • Experience:Intermediate
  • Area of Expertise:I'm Learning

Posted 07 August 2009 - 10:00 AM

View PostThomas Thomassen, on 07 August 2009 - 06:24 AM, said:

Looks ok. What's wrong? Error messages or no output? Have you tried to output the whole $row array to investigate it?



Well that one gives me a parse error
0

#4 User is offline   Thomas Thomassen 

  • HTTP 503
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,254
  • Joined: 30-April 07
  • Reputation: 10
  • Gender:Male
  • Location:Trondheim, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 07 August 2009 - 10:35 AM

What error?
When you experience problems where you're presented with errors it's best if you include that in your description. It helps narrowing down the cause. Otherwise it could be any number of things.
0

#5 User is offline   Rookie_Racer 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 51
  • Joined: 14-October 08
  • Reputation: 0
  • Experience:Intermediate
  • Area of Expertise:I'm Learning

Posted 07 August 2009 - 02:13 PM

Ok heres a live version

http://server9.hosti...eazyrew/ref.php

Thanks
0

#6 User is offline   Thomas Thomassen 

  • HTTP 503
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,254
  • Joined: 30-April 07
  • Reputation: 10
  • Gender:Male
  • Location:Trondheim, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 07 August 2009 - 02:20 PM

Ah! you forgot the ending semi-colon after you echo line.
0

#7 User is offline   Rookie_Racer 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 51
  • Joined: 14-October 08
  • Reputation: 0
  • Experience:Intermediate
  • Area of Expertise:I'm Learning

Posted 07 August 2009 - 02:35 PM

Thanj you, but now i got the ol' mysql_fetch_array() error, i cant remmeber whats wrong cos ima a mysql nub and havent done it for ages :(

Thanks

http://server9.hosti...eazyrew/ref.php
0

#8 User is offline   Rookie_Racer 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 51
  • Joined: 14-October 08
  • Reputation: 0
  • Experience:Intermediate
  • Area of Expertise:I'm Learning

Posted 07 August 2009 - 04:24 PM

Bump !
0

#9 User is offline   Thomas Thomassen 

  • HTTP 503
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,254
  • Joined: 30-April 07
  • Reputation: 10
  • Gender:Male
  • Location:Trondheim, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 07 August 2009 - 11:23 PM

View PostRookie_Racer, on 07 August 2009 - 02:35 PM, said:

Thanj you, but now i got the ol' mysql_fetch_array() error, i cant remmeber whats wrong cos ima a mysql nub and havent done it for ages :(

Thanks

http://server9.hosti...eazyrew/ref.php


What error?
0

#10 User is offline   scaz182 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 365
  • Joined: 01-April 08
  • Reputation: 2
  • Gender:Male
  • Location:Reading UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 07 August 2009 - 11:42 PM

Think it’s because you have a comma after subject:

SELECT refferals, subject, FROM gpt


Should be:

SELECT refferals, subject FROM gpt


Also refferals is spelt 'referrals' which could cause you problems, although it'd be fine if you have misspelt all instances ;)
0

#11 User is offline   Rookie_Racer 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 51
  • Joined: 14-October 08
  • Reputation: 0
  • Experience:Intermediate
  • Area of Expertise:I'm Learning

Posted 08 August 2009 - 01:44 PM

Its american, althought im getting deiffernt errors now :(

someone helped me code this right

<?
session_start();
$page="Refferals";
include"header.php";
include"mysql.php";

if($_SESSION['loggedin']==1){

$getuser=mysql_query("select * from users where id={$_SESSION['userid']}",$c);
echo $query;
$ui=mysql_fetch_array($getuser); 

$getuser=mysql_query("select * from users where id={$_SESSION['userid']}",$c) or die(mysql_error());
$ui=mysql_fetch_array($getuser);

$id = ($ui['username']); //change this as you need, can be queried from a form if you want
$query = "SELECT referrals FROM users WHERE id = ".$id;
$data = mysql_query($query) or die(mysql_error());
$results = mysql_fetch_array($data);

echo "<div align='center'>Referrals: ".$results['referrals']."<hr width='15%'></div>";


$id = ($ui['username']); //change this as you need, can be queried from a form if you want
$query = "SELECT id, username FROM users WHERE referrer = '[u][b]admin[/b][/u]'";
$data = mysql_query($query) or die(mysql_error());

echo "<div align='center'>";
while($results = mysql_fetch_array($data)) {
echo $results['id']." - ".$results['username']."<br />";
}
echo "</div>";

} else {
echo "<div align='center'>Please <a href='login.php?ref=refferals'>log in</a> to see your referrals.</div>";
}

?>


<table width="90%">
<tr>
<th colspan="2">
<div align="center">Refferals</div>
</th>
</tr>
<tr><th width="50%">User ID</th><th>Username</th></tr>
<tr>
<td valign="top">
<?
"<div align='center'>";
while($results = mysql_fetch_array($data)) {
echo $results['id'];
}
echo "</div>";
?>
</td>


<td valign="top">

</td>

</table>








<h2>Refferal Banners</h2>
<p class="post-by"></p>
<p>
Get paid faster and easier, by using these banners. Got a blog? Maybe a Site? Use these banners to get refferals.</p>
<p>
<br><u>HTML Code:</br></u>
<textarea name='styled-area' id='styled' onclick='this.focus();this.select()' readonly>><a href='<?=$siteurl;?>/?ref=<?=$ui['username'];?>'><img src='<?=$siteurl;?>/images/banner1.gif' border='0' /></a></textarea><br><br>
<br><u>BB Code:</br></u>
<textarea name='styled-area' id='styled' onclick='this.focus();this.select()' readonly>>[url='<?=$siteurl;?>/?ref=<?=$ui['username'];?>'][img]<?=$siteurl;?>/images/banner1.gif[/img][/url]></textarea><br><br>
</p>



<?

include"side.php";
include"footer.php";
?>



This query here
$id = ($ui['username']); //change this as you need, can be queried from a form if you want
$query = "SELECT id, username FROM users WHERE referrer = '[u][b]admin[/b][/u]'";
$data = mysql_query($query) or die(mysql_error());


More specificially the admin bit, when i log in on another account, eg 'test', it gives me this error

Quote

Unknown column 'test' in 'where clause'



Another thing is that it echo's the query fine, but when in a table it doent?

Anyone help?

I have msn if you ned it :)
0

#12 User is offline   Thomas Thomassen 

  • HTTP 503
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,254
  • Joined: 30-April 07
  • Reputation: 10
  • Gender:Male
  • Location:Trondheim, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 09 August 2009 - 11:51 AM

Quote

Its american

Even in US English I think it's spelled 'referrals'. Don't find it in any online dictionaries...#



As for your error: it's odd that it says the "column" test is unknown. Not sure why it looks for a column named test. Should be a field in the 'referrer' column if I read this correctly...

Quote

Another thing is that it echo's the query fine, but when in a table it doent?

I'm a bit confused with this. You mean when you try to format that data into an HTML table you get an error? But not when you dump it direclty with echo? (You use echo to generate the table - so I don't see why this should behave any different...)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users