latest 5 tutorials
9 posts
Page 1 of 1
hello,
was wondering if anyone can help me with my code below.
was wondering if anyone can help me with my code below.
Code: Select all
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. <?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";
?>
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.
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.
Code: Select all
This might work"SELECT * FROM `tutorials` WHERE `id`='$id' AND `title`='$title' ORDER BY `id` DESC LIMIT 5"
-Filip
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo
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>";
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>";
?>
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
you needed to include the variable via ".$username."<?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>";
?>
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that
yeah but how do i get it to login as mark and show it and anything else shows the other one.
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
9 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023