hello
:)
please I need your help :(
give me small example can do this:
how can display information in page if selected ,,,
look at this picture
hello
:)
please I need your help :(
give me small example can do this:
how can display information in page if selected ,,,
look at this picture
Where are you storing the information?
in mysql :)
In a table in the database
:)
ok here is the Demo .. Please feel free to look at the page source. The demo is a barebone.
Here is the code for the processor, pleas feel free to expand it to your requirements including database inclusions.
<?php
## this is for the ajaxform processor
if((isset($_POST['send_button'])) && (!empty($_POST['desc']))){
echo ($_POST['desc'])."<br/>";
## this is where you put your database query
}
else{
echo "You must select one option";
}
?>
Don't forget to sanitize all of the form submitted data, before adding them to your database.
how can do this with while ??
look at this code :
<?php
while( $row = mysql_fetch_array($result)) {
?>
<td> <input name="radio" type="radio" id="radio" value="<?php echo $row['id']?>"> </td>
<td ><?php echo $row['topic']; ?></td>
<td ><?php echo $row['author']; ?></td>
<td ><?php echo $row['date']; ?></td>
<?php
}
if((isset($_POST['save'])) && (!empty($_POST['radio']))){
echo ($_POST['radio'])."<br/>"; // how can print topic and author and date ??
}
else{
echo "You must select one option";
}
?>
then i want display information in anothor page :)
please help me :(
Hi,
Okay, please hang in there,.. I will re-write your codes.. Check back later. The demo I have provided is based on ajax, where there is no page reload on submit. Since you want to send the browser to a new page, then my example is not going to work. It will only work if javascript is disabled. I already provided this option on the demo page.
and, this should not be placed inside a loop e.g. for, foreach, while, etc..
if((isset($_POST['save'])) && (!empty($_POST['radio']))){
echo ($_POST['radio'])."<br/>"; // how can print topic and author and date ??
Let me just finished what I am currently doing and I will get back to this question ASAP.
Ok, I am back to tackle this. Please bear in mind that my style of coding is somewhat different, but it will make a lot of sense if given the proper analysis logic wise. My head is always wired like this -> logic ->View -> template system.
Since there is no way for me to teach someone how to work on php frameworks and templating system in this short of time, I will be using the same coding techniques I have implemented when I was 13 years of age, and when I was barely learning how to write php programs. Even after 6 years, I am still surprised on how my mindset able to creatively do this.
I am hoping that this technique will help the new comers in php language. Although it is not perfect, I truly believe this will truly help people how to organize their codes.
**!WARNING AND DISCLAIMERS! **This script is not sanitized.. I want you to do it yourself, for you to gain an actual experience on sanitizing data for database query. I also don't give or extend any warranties for this script. The final version of this script must be all based on your own server environment.
Here we go..
STEP ONE:
On your localhost create 2 two directories. Name these directories as includes and template
STEP TWO:
Copy codes below and name it index.php or whatever name you want.
filename: index.php or whatever.php
<?php
## This is sample script written by PoorBoy or Veedeoo.
## this is the logic page : index.php
## define view page.
define('TPL_DIR','template');
## define includes directory. This is where you put your function
define('INC_DIR','includes');
## define your query
$sql = "(SELECT * FROM YOUR_TABLE WHERE COL_NAME = 'COL_VALUE' ORDER by 'title')";
include_once((INC_DIR)."/function.php");
## we include the template directory
include_once((TPL_DIR)."/home.tpl");
?>
How to set this page up? First, you need to change this to your own database
$sql = "(SELECT * FROM YOUR_TABLE WHERE COL_NAME = 'COL_VALUE' ORDER by 'title')";
FileName: template/home.tpl Copy and Save codes below as homet.tpl and upload to your template directory.
<!-- This is the simple template file. Not bad if you are trying to avoid a system like smarty, dwoo, twig, and others. -->
<html>
<head>
</head>
<body>
<div>
<table cellpadding = "3" cellspacing = "3">
<tr bgcolor = "teal">
<td>Select</td><td>Title</td><td>Author</td><td>Date</td></tr>
<form action = "process.php" method ="post">
<! PHP codes begins -->
<?php
$data = simple_func($sql);
foreach($data as $info){
?>
<tr>
<td><input type = "radio" name = "id" value = "<?php echo $info[0];?>"></td>
<td><?php echo $info[1];?></td>
<td><?php echo $info[2];?></td>
<td><?php echo $info[3];?></td>
<?php
}
?>
<!-- end of PHP codes -->
<tr>
<td colspan= "4"><input type="submit" name = "submit" value ="GO" /></td>
</tr>
</form>
</div>
</body>
</html>
Explanation about the page above.. $info[1] refers to the database table columns from left to right.. e.g 0 1 2 3 4 ..
STEP THREE
Copy and save codes below as process.php..
<?php
## This is sample script only written by PoorBoy or Veedeoo.
## this is the logic page process.php
## define view page.
define('TPL_DIR','template');
## define includes directory. This is where you put your function
define('INC_DIR','includes');
if(isset($_POST['submit']) && (!empty($_POST['id']))){
## define sql query
$sql = "(SELECT * FROM YOUR_TABLE WHERE id = '".$_POST['id']."')";
include_once((INC_DIR)."/function.php");
## we include the template directory
include_once((TPL_DIR)."/process.tpl");
}
?>
You need to set this up to your database table
$sql = "(SELECT * FROM YOUR_TABLE WHERE id = '".$_POST['id']."')";
FileName : process.tpl copy and save codes below as process.tpl. Upload this file in your template directory
<html>
<head>
</head>
<body>
<div>
<! PHP codes begins -->
<?php
$data = simple_func($sql);
foreach($data as $info){
?>
<!-- put your html tags here to style the output -->
<?php echo $info[1];?>
<?php
}
?>
<!-- end of PHP codes -->
</div>
</body>
</html>
STEP FOUR:
This is the final step.. and we will creating the function.php
Filename: includes/function.php . Copy and save as function.php in your includes directory.
<?php
## filename: function.php
function simple_func($sql){
## define your database connection credentials
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_database ="YouRDATABASEName";
$conn = mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
$db = mysql_select_db($db_database,$conn) or die(mysql_error());
$result = mysql_query($sql, $conn) or die(mysql_error());
## And we display the results
while($row = mysql_fetch_array( $result ))
{
$data[] = $row;
}
## we return the data
return $data;
}
How to set this function.php. Update the database connection credentials to your own database.
Last and FINAL STEP:
It is common for some people who are definitely bored browsing the Internet. Sometimes, they are looking for sites holes and want to access your files directly. In this case, our template directory files are vulnerable for being viewed as file source. To prevent such weaknesses, we need to creat an .htaccess file to protect it from spying eyes.
**Filename: .htaccess **copy and save as .htaccess ..
<files *.tpl>
order allow,deny
deny from all
</files>
SUGGESTION FOR IMPROVEMENTS
Since that I just jotted this script down, based on how I will right a simple script without the benefits of smarty and all those stuffs I have learned over the years. The process was fast. Few minutes give me this codes. However, it is still has a lot of room to grow. For instance, I would separate the <head> section of the tpl files and save it as head.php , and include it as head.tpl
That' it.. I am really sorry for the long and boring post....
Don't forget to sanitize the form input to fro the database.. that is your homework.
Just a humble reminder, they don't allow double posting of the same question like the one you posted Here
The reason is that, it is really hard to track questions being posted here on a daily basis... I mean lots and lots of them with different flavors and colours... :)
veedeoo Thank you for your cooperation :)
I wish you all the best
"
I will try it :)
"
Hay there veedeoo I work in the same code with my friend "don't give
we have no Experience in Smarty or Zend framework
I've seen that you have used some Smarty Syntax.. ".tpl"
How can we replace it
My friend Iis working on "DEV" and "wamp Server"
and I work with "Aptana" and "xampp".
we don't intend to make it large
do we essinstially need Smarty or Zend?
bear with us .
@smallSteps,
No..don't worry about the .tpl extension.. that is a valid php extension. I just have to write the codes this way to demonstrate how to organize the codes and to make it a lot cleaner. I did not put any smarty or anything like that on the codes above. In all of my coding work, I barely throw php codes inside a barrel along with html tags... the .tpl files here still have those mashup but it is very minimal, which is pretty good without using the smarty.
The only different methods I've use is this $data[] = $row; which is still able to work in all version of php, and don't need smarty or any special parser...
Just follow through the codes, and you will a good hang to it, and you will realize that it is not using any smarty or Zend. It is just a simple php codes organized to follow the zimple logic -> view principle.. that's all :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.