latest 5 tutorials

9 posts Page 1 of 1
Contributors
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

latest 5 tutorials
Mark
hello,

was wondering if anyone can help me with my code below.
Code: Select all
 <?php

    require ("scripts/connect.php");
    $query = mysql_query("SELECT * FROM tutorials WHERE id='$id' And title='$title' ORDER BY id DESC LIMIT 5");
    $numrows = mysql_num_rows($query);
    if ($numrows > 0){
        while($row = mysql_fetch_assoc($query)){
            $title = $row['title'];
            
            echo "$title";
        }
    }
    else
        echo "NO tutorials were found";

?>
im trying to get it to show the latest 5 tutorials in my database but it keeps coming up saying NO tutorials were found even though there is some in the database.
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Re: latest 5 tutorials
CodenStuff
My PHP isn't the best but try...
Code: Select all
<?php

    require ("scripts/connect.php");
    $query = mysql_query("SELECT * FROM tutorials WHERE id='$id' And title='$title' ORDER BY id DESC LIMIT 5");
    $numrows = mysql_num_rows($query);
    if ($numrows > 0){
        while($row = mysql_fetch_assoc($query)){
            $title = $row['title'];
            
            echo $title;
        }
    }
    else
{
        echo "NO tutorials were found";
}
?>
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Re: latest 5 tutorials
Mark
hello cody,

it seems to still be doing the same.
http://www.mbappz.com
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Re: latest 5 tutorials
CodenStuff
Could be your query change it to..
Code: Select all
"SELECT * FROM tutorials ORDER BY id DESC LIMIT 5"
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: latest 5 tutorials
Filip
Code: Select all
"SELECT * FROM `tutorials` WHERE `id`='$id' AND `title`='$title' ORDER BY `id` DESC LIMIT 5"
This might work

-Filip
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Re: latest 5 tutorials
Mark
this one has been resolved.

another quick question.

with the code below is it possible if i login as say Mark as the username is shows


echo "<table>
<tr>
<td><a href='profile.php?id=$userid'>$username</a></td>
<td><a href='logout.php'>Logout</a></td>
<td><''>Edit Tutorial</a></td>
</tr>
</table>";

if they are not Mark then it shows

echo "<table>
<tr>
<td><a href='profile.php?id=$userid'>$username</a></td>
<td><a href='logout.php'>Logout</a></td>
</tr>
</table>";
Code: Select all
<?php

if ($username){
	echo "<table>
	<tr>
		<td><a href='profile.php?id=$userid'>$username</a></td> 
		<td><a href='logout.php'>Logout</a></td>
	</tr>
	</table>";
}
else
	echo "<form action='login.php' method='post'>
	<center><table>
	<tr>
		<td>Username</td>
		<td><input type='text' name='username' class='textbox' size='25'></td>
		<td><a href='register.php'>Register</a></td>
	</tr>
	<tr>
		<td>Password</td>
		<td><input type='password' name='password' class='textbox' size='25'></td>
		<td><input type='submit' name='loginbtn' value='Login' class='button'></td>
	</tr>
	</table></center>
	</form>";

?>
http://www.mbappz.com
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1891
Joined: Wed Dec 16, 2009 9:56 pm

Re: latest 5 tutorials
zachman61
Mark wrote:
this one has been resolved.

another quick question.

with the code below is it possible if i login as say Mark as the username is shows


echo "<table>
<tr>
<td><a href='profile.php?id=$userid'>$username</a></td>
<td><a href='logout.php'>Logout</a></td>
<td><''>Edit Tutorial</a></td>
</tr>
</table>";

if they are not Mark then it shows

echo "<table>
<tr>
<td><a href='profile.php?id=$userid'>$username</a></td>
<td><a href='logout.php'>Logout</a></td>
</tr>
</table>";
Code: Select all
<?php

if ($username){
	echo "<table>
	<tr>
		<td><a href='profile.php?id=$userid'>$username</a></td> 
		<td><a href='logout.php'>Logout</a></td>
	</tr>
	</table>";
}
else
	echo "<form action='login.php' method='post'>
	<center><table>
	<tr>
		<td>Username</td>
		<td><input type='text' name='username' class='textbox' size='25'></td>
		<td><a href='register.php'>Register</a></td>
	</tr>
	<tr>
		<td>Password</td>
		<td><input type='password' name='password' class='textbox' size='25'></td>
		<td><input type='submit' name='loginbtn' value='Login' class='button'></td>
	</tr>
	</table></center>
	</form>";

?>
Code: Select all
<?php
if (isset($username)){
	echo "<table>
	<tr>
		<td><a href='profile.php?id=$userid'>".$username."</a></td> 
		<td><a href='logout.php'>Logout</a></td>
	</tr>
	</table>";
}
else
	echo "<form action='login.php' method='post'>
	<center><table>
	<tr>
		<td>Username</td>
		<td><input type='text' name='username' class='textbox' size='25'></td>
		<td><a href='register.php'>Register</a></td>
	</tr>
	<tr>
		<td>Password</td>
		<td><input type='password' name='password' class='textbox' size='25'></td>
		<td><input type='submit' name='loginbtn' value='Login' class='button'></td>
	</tr>
	</table></center>
	</form>";
?>
you needed to include the variable via ".$username."
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Re: latest 5 tutorials
Mark
yeah but how do i get it to login as mark and show it and anything else shows the other one.
http://www.mbappz.com
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

Re: latest 5 tutorials
Scottie1972
Mark wrote:
yeah but how do i get it to login as mark and show it and anything else shows the other one.
use cookies setup for your domain to remeber the user's name.
as long as that cookie is good and exist. the user's name will always be there to be accessed.

create the cookie at the same time you run your login script.

$username = $_SETCOOKIE("Username", ".$row['username'].", cookie_expire_date)'

more information on using cookies
read this webpage http://www.tizag.com/phpT/phpcookies.php
Image
9 posts Page 1 of 1
Return to “Help & Support”