SitePoint Sponsor |
|
User Tag List
Results 101 to 125 of 151
-
Mar 31, 2006, 04:51 #101
Originally Posted by jelena
exept for C++, and it was just introductions if you know what i mean
(input, output, control statment(if, else, while and for)) and simple understanding of pointers, as will as the basic use of functions,
then i stoped for almost 1 year and a half,
i got an internet connection last year, reading online about almost everything, webdevelopment, buissnes, name it exept politics
so i saw my self really behind in IT industry (am an IT student).
so a started from then.
reading about OS (windows, Linux)
business and IT (ecommers)
now am into webdevelopment (and i like it).
in general i support open sorce, i like anything realated to open source.
so my first chose was PHP and Mysql.
i almost gave up
i moved to HTML\xHTML the CSS2 (i love it)
now am back to PHP and MYSQL (wish me luck)
then may be a bit of Java Script
then to OO with PHP
so i hope i can achive this before i gratuate which is by year end.
-
Mar 31, 2006, 05:05 #102
please i have this silly Q.
if am passing a variable through url and i want the funnction to get the variable
and use it then return a instruction
how to make the function get the variablesilly isn't ?
-
Mar 31, 2006, 05:05 #103
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by auricle
One cannot learn everything in one week. As I already mentioned in my posts here, there is lot more in php.
I've had students before. I have my own aproach of teaching. Best aproach for learing I've experienced so far is STEP BY STEP one.
For example, before jumping into classes, I would rather teach him about code separation.
Originally Posted by auricle
Anyway, I don't want this beautiful thread to go offtopic. Please, if you'd like to disccuss OO, take a look at PHP Application Design forum.-- Jelena --
-
Mar 31, 2006, 05:09 #104
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by hisham777
PHP Code:funciton echo_me($variable)
{
if($variable != "")
{
echo $variable;
}
}
PHP Code:$var = $_GET["var"];
PHP Code:echo_me($var);
PHP Code:$var = $_GET["var"];
$new = return_me($var);
function return_me($variable)
{
return $variable;
}
-- Jelena --
-
Mar 31, 2006, 05:15 #105
ok after trying i came up with this, am not sure how good it is but its working
i added a new function in the functions.php
PHP Code:function article_delete($article_id)
{
$sql = "DELETE FROM articles WHERE articleID = '".$article_id."'";
my_query($sql);
return true;
}
and the delete.php
PHP Code:include_once "common.php";
$article_id = $_GET['article_ID'];
if(article_delete($article_id))
{
echo "Ok";
}
else
{
echo "error ";
echo "Article,,,ID : ".$article_id;
}
-
Mar 31, 2006, 05:15 #106
am not eve sure if its correct ????
-
Mar 31, 2006, 05:20 #107
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by hisham777
With one only modification:
You don't need an if here
PHP Code:$article_id = $_GET['article_ID'];
if(article_delete($article_id))
{
echo "Ok";
}
else
{
echo "error ";
echo "Article,,,ID : ".$article_id;
}
So, it would be just fine to do:
PHP Code:include_once "common.php";
$article_id = $_GET['article_ID'];
article_delete($article_id)
echo "Deleted";
-- Jelena --
-
Mar 31, 2006, 05:31 #108
Originally Posted by jelena
and this post.
article_delete($article_id)
her am calling the function in the delete.php
and the function will take the value of $article_id
and process it in the function then return ok.
the compiler will go to the next line and echo "Deleted";?
if its correct then am starting to pick up functions
if not correct i have to read a bit about the compiler behaviour.
-
Mar 31, 2006, 05:42 #109
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by hisham777
As I explained in previous post, we don't need to assign what function returns to a variable, as it will always return true.-- Jelena --
-
Mar 31, 2006, 05:57 #110
ok thats bring me to another Q.
now am trying to code afunction to read article.
with my basic understanding. this is the style of the function
name the function
function article_read($article_id)
the SQL quiry
$sql = "SELECT FROM articles WHERE articleID = '".$article_id."'";
now here is the confution, can i still use what i usally use
$res = mysql_query($sql);
$num = mysql_fetch_assoc($res);
my_query($sql);
but it return the $num like this
return $num;
-
Mar 31, 2006, 06:06 #111
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Yes, basically, that's correct.
PHP Code:function article_read($article_id)
{
$sql = "SELECT article_name, summarty, date_added, article_content FROM articles WHERE articleID = '".$article_id."'";
$res = mysql_query($sql);
if(mysql_num_rows($res) != 0)
{
$num = mysql_fetch_assoc($res);
return $num;
}
else
return false;
}
PHP Code:$article = article_read($article_id);
When it's false, that means that article with provided ID doesn't exist.
So, before displaying it, we would perform a check
PHP Code:if(!$article)
{
echo "article doesn't exist";
}
else
{
//dispay article
}
-- Jelena --
-
Mar 31, 2006, 06:37 #112
a small change to this
Originally Posted by jelena
PHP Code:include_once "common.php";
$article_id = $_GET['article_ID'];
$article = article_read($article_id);
if(!$article)
{
echo "article doesn't exist";
}
else
{
echo '<table width="720" border="1" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="181" height="30" valign="top">Name </td>
<td width="539" valign="top">';
echo $article["article_name"];
echo '</td>
</tr>
<tr>
<td height="30" valign="top">Summary</td>
<td valign="top">';
echo $article["summary"];
echo '</td>
</tr>
<tr>
<td height="30" valign="top">Author</td>
<td valign="top">';
echo $article["author"];
echo '</td>
</tr>
<tr>
<td height="30" valign="top">Content</td>
<td rowspan="2" valign="top">';
echo $article["article_content"];
echo '</td>
</tr>
<tr>
<td height="190"> </td>
</tr>
<tr>
<td height="42" valign="top">Note</td>
<td valign="top">';
echo $article["notes"];
echo '</td>
</tr>
<tr>
<td height="30" valign="top">Date added </td>
<td valign="top">';
echo $article["date_added"];
echo '</td>
</tr>
<tr>
<td height="30" valign="top">Status</td>
<td valign="top">';
echo $article["status"];
echo '</td>
</tr>
</table>';
//dispay article
}
-
Mar 31, 2006, 06:44 #113
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Now, let make function flexible for usage in frontend and admin zone:
PHP Code:function article_read($article_id, $frontend = false)
{
$sql = "SELECT article_name, summary, author, article_content, notes, date_added, status";
$sql .= " FROM articles";
$sql .= " WHERE articleID = '".$article_id."'";
if($frontend)
$sql .= " AND Status = '1'";
$res = my_query($sql);
if(mysql_num_rows($res) != 0)
{
$num = mysql_fetch_assoc($res);
return $num;
}
else
{
return false;
}
}
Now when calling funtion in frontend, we will call it this way:
PHP Code:$article = article_read($article_id, true)
This is also a good example for seeing purpose of writting functions.Last edited by jelena; Mar 31, 2006 at 06:51. Reason: added more explanations
-- Jelena --
-
Mar 31, 2006, 06:52 #114
cooooool never thought of the display yat though. am more on the admin side still.
but the function its Wow, it make me realize what i was missing in programming
now i have to think how to write a function that edit the articles(am excited).
-
Mar 31, 2006, 06:55 #115
Wo Wo Wo WO, sorry i did not notice this.
Originally Posted by jelena
-
Mar 31, 2006, 06:59 #116
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by hisham777
Let me know if you are stuck somewhere.
I don't want to write it for you, I'd like to see you try first without help-- Jelena --
-
Mar 31, 2006, 08:09 #117
ok, i made use of the function article_read($article_id) to fatch the article
and diplay it in the form, and its working.
ist ok to make use of the same function or you have something in mind ?
PHP Code:<?php
include_once "common.php";
$article_id = $_GET['article_ID'];
$article = article_read($article_id);
if(!$article)
{
echo "article doesn't exist";
}
else
{
echo '<html><body>
<form action="edit2.php" method="post">
<p>
<input name="articleID" type="hidden" id="articleID" value="';
echo $article["articleID"];
echo ' "/>
<br />
Article Name <br />
<input name="articlename" type="text" id="articlename" value="';
echo $article["article_name"];
echo ' " size="80" maxlength="80" />
<br />
Summary <br />
<input name="summary" type="text" id="summary" value="';
echo $article["summary"];
echo ' "size="80" />
<br />
Author <br />
<input name="author" type="text" id="author" value="';
echo $article["author"];
echo '" size="80" maxlength="30" />
<br />
Article Content </p>
<p>
<textarea name="articlecontent" cols="80" rows="7" id="articlecontent">';
echo $article["article_content"];
echo '</textarea>
<br />
<br />
Notes <br />
<input name="notes" type="text" id="notes" value="';
echo $article["notes"];
echo '" size="80" maxlength="300" />
<br />
Date Posted <br />
<input name="date" type="text" id="date" value="';
echo $article["date_added"];
echo '" size="80" maxlength="30" />
<br />
Status <br />
<input name="status" type="text" id="status" value="';
echo $article["status"];
echo '" size="7" maxlength="80" />
<br />
<input name="" type="submit" value="Submit" />
</p>
</form>
</body>
</html>';
}
?>
-
Mar 31, 2006, 08:11 #118
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
I would create a separate function for editing articles, but basically you can copy/paste all checks from function for adding articles..
I would also make Status as a checkbox (but only if you don't have intention to add more statuses, if you do, then I would use select).-- Jelena --
-
Mar 31, 2006, 09:30 #119
there is a special way to handle the hidden fields !!??
can i use the same way i use with text fields ?
-
Mar 31, 2006, 09:33 #120
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by hisham777
-- Jelena --
-
Mar 31, 2006, 09:43 #121
i know its not what you expected
ok i dont know if its the right way?
but there is an error.its my best at the moment.
9hours stright infront of the computer.
the function .
PHP Code:function article_update($article)
{
if(empty($article["article_name"]))
{
$_SESSION["error"] = "Please enter The Article Name";
return false;
}
else if(empty($article["summary"]))
{
$_SESSION["error"] = "Please enter a summary";
return false;
}
else if(empty($article["article_content"]))
{
$_SESSION["error"] = "Please enter a content";
return false;
}
$sql = "UPDATE articles "."SET";
$sql .=" article_name = '".$article["article_name"]."'";
$sql .=" summary = '".$article["summary"]."'";
$sql .=" author = '".$article["author"]."'";
$sql .=" article_content = '".$article["article_content"]."'";
$sql .=" notes = '".$article["notes"]."'";
$sql .=" status = '".$article["status"]."'";
$sql . "WHERE articleID = '".$article["articleID"]."'";
my_query($sql);
return true;
}
the error
Database error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'summary = 'mvbm ' author = 'vbmcvbmcv' article_content = ',n,cbn,nbbn,ddaw' note' at line 1
Query was (UPDATE articles SET article_name = 'bvnvb ' summary = 'mvbm ' author = 'vbmcvbmcv' article_content = ',n,cbn,nbbn,ddaw' notes = 'bcn,cbn,bn,' status = '0') in file
-
Mar 31, 2006, 10:04 #122
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:$sql = "UPDATE articles SET";
$sql .=" article_name = '".$article["article_name"]."'";
$sql .=", summary = '".$article["summary"]."'";
$sql .=", author = '".$article["author"]."'";
$sql .=", article_content = '".$article["article_content"]."'";
$sql .=", notes = '".$article["notes"]."'";
$sql .=", status = '".$article["status"]."'";
$sql .= " WHERE articleID = '".$article["articleID"]."'";
-- Jelena --
-
Mar 31, 2006, 10:22 #123
i change it to this
PHP Code:$sql = "UPDATE articles "."SET";
$sql .=" article_name = '".$article["article_name"]."'";
$sql .=" summary = '".$article["summary"]."'";
$sql .=" author = '".$article["author"]."'";
$sql .=" article_content = '".$article["article_content"]."'";
$sql .=" notes = '".$article["notes"]."'";
$sql .=" status = '".$article["status"]."' WHERE articleID = '".$article["articleID"]."'";
Database error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'summary = 'kjgykjdyk ' author = 'jgykfgtyk' article_content = 'gykgkgkghkbjkkjjk' at line 1
Query was (UPDATE articles SET article_name = 'l;;;udyjudy ' summary = 'kjgykjdyk ' author = 'jgykfgtyk' article_content = 'gykgkgkghkbjkkjjkn,' notes = 'hkghkkhk' status = '0' WHERE articleID = '32 ') in file
-
Mar 31, 2006, 10:26 #124
better still, am to tired, i think i should go to sleep.
and 2moro morning i shall construct the function from scratch.
any advice to consider before i start doing it again?
as for good night and thanks jelena.
-
Mar 31, 2006, 11:01 #125
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Still no commas where you should have them in your query:
PHP Code:$sql = "UPDATE articles "."SET";
$sql .=" article_name = '".$article["article_name"]."'";
$sql .=", summary = '".$article["summary"]."'";
$sql .=", author = '".$article["author"]."'";
$sql .=", article_content = '".$article["article_content"]."'";
$sql .=", notes = '".$article["notes"]."'";
$sql .=", status = '".$article["status"]."' WHERE articleID = '".$article["articleID"]."'";
-- Jelena --
Bookmarks