So, it means you fixed the Warning you were getting?
Which page would you like to do next and what questions do you have about making them?
| SitePoint Sponsor |
So, it means you fixed the Warning you were getting?
Which page would you like to do next and what questions do you have about making them?
-- Jelena --
yah the warning was sentax error fixed.
i think all start coding the main admin page using XHTML & CSS
then all start adding some functionalitys like how many record in the DB, total heading
and shown articles, then all move to coding delete page were the admin can read add delete change the status...etc.
the idea is to combine the the display with the delete something like this
article Name----Article summary----Date added----Status----Action To Take
summercamp......tripToJapan..........13-04-2006......active......read--Edite--Delete
what do you think ?
Yep, that's the way I would go!
You can also create a filter/little search on that page with one select where he will be able to choose if he wants to see only pending articles or only active ones.
If you get stucked with it, just post your code and we'll try to solve the problem.
-- Jelena --
thanks jelena apriciated
the mainpage of the addmin will be something like this
any extra functionallty you think should be there please let me know
thanks
see attachment
that layout is fine, but maybe you don't need those links but just one select with those options:
show all/approved/not approved
Just my opinion.
-- Jelena --
sorry i dont realy understand what you mean.
ah do you mean i remove the links
Display All, Display Active and Display Inactive
to
Show all/Approved/Not Approved
Nope, but create this:
Code:Display <form action="" method="get"> <select name="status"> <option value="">All</option> <option value="1">Active</option> <option value="0">Inactive</option> </select> </form>
Last edited by jelena; Mar 28, 2006 at 09:39.
-- Jelena --
ok i did a small code for the number of rows in the table its not efficient![]()
but it does the job any suggestions on making it better.
PHP Code:<?php
$dbhost = 'localhost';
$dbuser = 'roots';
$dbpass = '555456';
$dbname = 'site';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('connecting to MySQL failed');
mysql_select_db($dbname);
$result1= mysql_query("SELECT * FROM articles");
$result2= mysql_query("SELECT * FROM articles WHERE status = '1'");
$result3= mysql_query("SELECT * FROM articles WHERE status = '0'");
$num_rows1 = mysql_num_rows($result1);
echo "total record " .$num_rows1;
echo '<br />';
$num_rows2 = mysql_num_rows($result2);
echo "approvid records " .$num_rows2;
echo '<br />';
$num_rows3 = mysql_num_rows($result3);
echo "not approvid records records " .$num_rows3;
echo '<br />';
mysql_close($conn);
?>![]()
Haven't tested this, but you will get an idea how you could do it:
PHP Code:<?php
$status = $_GET["status"];
$dbhost = 'localhost';
$dbuser = 'roots';
$dbpass = '555456';
$dbname = 'site';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('connecting to MySQL failed');
mysql_select_db($dbname);
$sql = "SELECT * FROM articles";
if($status != "")
$sql .= " WHERE Status = '".$status."'";
$result1= mysql_query($sql);
$num_rows1 = mysql_num_rows($result1);
echo "total record for ";
if($status == "")
echo "all records";
elseif($status == 1)
echo "approved records";
else
echo "pending records";
echo " is ".$num_rows1;
echo '<br />';
mysql_close($conn);
?>
-- Jelena --
very intersting nesting
but what does this do ?
if($status != "")
$sql .= " WHERE Status = '".$status."'";
i got it very coool intersting WOW
1 query instead of 3Cool indeed
![]()
-- Jelena --
please tell me what do you think of this
i made it as a brief discription of all the articles
and all all add a buttens for delete and edite on each article listed.
but there is a warning for this code
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in E:\Practise\test1\listarticles.php on line 69
PHP Code:<?php
$status = $_POST["status"];
$dbhost = 'localhost';
$dbuser = 'roots';
$dbpass = '555456';
$dbname = 'site';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('connecting to MySQL failed');
mysql_select_db($dbname);
$sql = "SELECT * FROM articles";
if($status != "")
$sql .= " WHERE Status = '".$status."'";
$result1= mysql_query($sql);
$num = mysql_num_rows($result1);
if($status == ""){
for($i=0;$i<$num;$i++) { // Start looping
$array = mysql_fetch_array($result1);
$articleid = $array[0];
$articlename = $array[1];
$summary = $array[2];
$date = $array[6];
echo $articleid;
echo $articlename;
echo $summary;
echo $date;
echo "<br />";
}
}
elseif($status == 1)
for($i=0;$i<$num;$i++) { // Start looping
$array = mysql_fetch_array($result1);
$articleid = $array[0];
$articlename = $array[1];
$summary = $array[2];
$date = $array[6];
echo $articleid;
echo $articlename;
echo $summary;
echo $date;
echo "<br />";
}
else{
for($i=0;$i<$num;$i++) { // Start looping
$array = mysql_fetch_array($result1);
$articleid = $array[0];
$articlename = $array[1];
$summary = $array[2];
$date = $array[6];
echo $articleid;
echo $articlename;
echo $summary;
echo $date;
echo "<br />";
}
}
mysql_free_result($sql);
mysql_close($conn);
?>
Try this out:
PHP Code:<?php
$status = $_POST["status"];
$dbhost = 'localhost';
$dbuser = 'roots';
$dbpass = '555456';
$dbname = 'site';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('connecting to MySQL failed');
mysql_select_db($dbname);
$sql = "SELECT * FROM articles";
if($status != "")
$sql .= " WHERE Status = '".$status."'";
$result1= mysql_query($sql);
$num = mysql_num_rows($result1);
echo "Results for";
if($status == "")
echo "all articles.";
if($status == 1)
echo "active articles.";
if($status == 0)
echo "inactive articles.";
while($array = mysql_fetch_assoc($result1))
{
echo $array["ArticleID"]; // element coresponds to field name in db table, change accordingly
echo $array["ArticleName"]; // element coresponds to field name in db table, change accordingly
echo $array["Summarty"]; //element coresponds to field name in db table, change accordingly
echo $array["Date"]; //element coresponds to field name in db table, change accordingly
echo "<br />";
}
mysql_free_result($result1);
mysql_close($conn);
?>
You don't need 3 for loops. It's ok to go with only one while loop.
-- Jelena --
hahahhahahaha
you are killing me with 3 to 1
by the way how did you make it to this level in php and mysql ?
some advices please
i still have this warning according to the php manual it should be fine using mysql_free_result() to free the memory i dont get it![]()
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in E:\Practise\test1\listarticles.php on line 69
After you finish this small system, you'll realize this is just the beginning of php/mysql programming
Seriously, there is much more then submitting forms/inserting records in db and fetching them. Although, you have chosen perfect system for start!
Practice, practice, practice and you'll very easily accomplish good level of knowledge.
Advice:
1. learn to use PHP manual (that should be your best friend for learning)
In other words, you don't need to call it.Originally Posted by PHP Manual
When you get at the point that you have too much articles, it will be time for per page![]()
-- Jelena --
Taking about paging whats he princible of it where to start.
if my guess is right the guery will be LIMIT. or may be its not the time for it
there are othere things in the system first.
thanks jelena for the advice
I would suggest you to finish the system firstly, view/edit pages in admin section, and I could explain you my way of handling pagination, but yes, I use LIMIT in query.
-- Jelena --
Ok then am still thinking of the style to use for the admin
my idea is
when the admin click show all the article will be displayed
see the attachment
or better still just display the article name and the date and there are
options to read, delete, edite and activate
i would love to see your comment
thanks
Last edited by hisham777; Mar 29, 2006 at 04:06.
While waiting for attachment to get approved, I would say what I would do: on page which lists all articles, I would display only title, date, author and options to read/edit/delete. It's more cleaner that way.
-- Jelena --
thats what i mean
ok then all get right into it
thanks
is this a right approch
PHP Code:while($array = mysql_fetch_assoc($result1))
{
echo '<table width="720" border="1" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="140" height="40" valign="top">Article Name: </td>
<td width="460" valign="top">'.$array["article_name"].'</td>
<td width="120" valign="top"><a href="Read.php?article_ID=' . $array["articleID"] . '">Read </a></td>
</tr>
<tr>
<td height="40" valign="top">Date Posted: </td>
<td valign="top">'.$array["date_added"] .'</td>
<td valign="top"><a href="Edit.php?article_ID=' . $array["articleID"] . '">Edit </a></td>
</tr>
<tr>
<td height="40" valign="top">Author: </td>
<td valign="top">'.$array["author"] .'</td>
<td valign="top"><a href="delete.php?article_ID=' . $array["articleID"] . '">Delete </a></td>
</tr>
</table>';
What about something like this:
PHP Code:<table width="720" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>Title</td>
<td>Date</td>
<td>Author</td>
<td>Action</td>
</tr>
<?php
while($array = mysql_fetch_assoc($result1))
{
?>
<tr>
<td><?php echo $array["article_name"];?></td>
<td><?php echo $array["date_added"];?></td>
<td><?php echo $array["article_author"];?></td>
<td><a href="Read.php?article_ID=<?php echo $array["articleID"] ;?>">View</a> |
<a href="Edit.php?article_ID=<?php echo $array["articleID"] ;?>">Edit</a> |
<a href="delete.php.php?article_ID=<?php echo $array["articleID"] ;?>">Delete</a>
</td>
</tr>
<?php
}
?>
</table>
-- Jelena --


You could of course just hire Jelena.......
Mike Swiffin - Community Team Leader
Only a woman can read between the lines of a one word answer.....
I started out with nothing... and still got most of it left!
Bookmarks