
arunpatal
Members-
Posts
273 -
Joined
-
Last visited
Everything posted by arunpatal
-
Working with the help of encodeURIComponent() and yours Thanks alot
-
Hi, Sending value via post method works just fine till i typed & in text feild. It just stop there and dose not show echo anything after & and & Here is the test.php page <html> <head> <script language="JavaScript" type="text/javascript"> function ajax_post(){ // Create our XMLHttpRequest object var hr = new XMLHttpRequest(); // Create some variables we need to send to our PHP file var url = "return.php"; var fn = document.getElementById("first_name").value; var ln = document.getElementById("last_name").value; var vars = "firstname="+fn+"&lastname="+ln; hr.open("POST", url, true); // Set content type header information for sending url encoded variables in the request hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // Access the onreadystatechange event for the XMLHttpRequest object hr.onreadystatechange = function() { if(hr.readyState == 4 && hr.status == 200) { var return_data = hr.responseText; document.getElementById("status").innerHTML = return_data; } } // Send the data to PHP now... and wait for response to update the status div hr.send(vars); // Actually execute the request document.getElementById("status").innerHTML = "processing..."; } </script> </head> <body> <table width="100%"> <td width="50%" valign="top"> <input id="first_name" name="first_name" type="text" /> <input id="last_name" name="last_name" type="text" /><br> <input name="myBtn" type="submit" value="Submit Data" onClick="javascript:ajax_post();"> </td> <td width="50%" valign="top"> <div id="status"></div> </td> </table> </body> </html> And here is the page from which ajax will bring the msg.... <?php if (isset($_POST['firstname'])) { echo 'Thank you '. $_POST['firstname'] . ' ' . $_POST['lastname'] . ', says the PHP file'; } ?>
-
Hi, I am fetching username.... This is PHP Code for fetching.. <?php include("ajax.php"); include("connection.php"); $sql = mysql_query("select * from $demo") or die (mysql_error()); while ($row = mysql_fetch_array($sql)){ echo '<input id="name" value="'.$row["username"].'" size="50" type="text" />'; echo '<input type="submit" value="Add Category" onClick="javascript:test_function();"><br>'; } ?> <div id="status"> </div> Now i am passing username value to ajax by clicking submit..... Here is Ajax Code <script language="JavaScript" type="text/javascript"> function test_function(){ var hr = new XMLHttpRequest(); var url = "php.php"; if (document.getElementById("name")){ var ca = document.getElementById("name").value; var vars = "name="+ca; } hr.open("POST", url, true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if(hr.readyState == 4 && hr.status == 200) { var return_data = hr.responseText; document.getElementById("status").innerHTML = return_data;}} hr.send(vars); document.getElementById("status").innerHTML = "<img class='loading' src='load.gif' alt='loading...' />";} </script> Now am echoing the passed value <?php echo $_POST["name"]; ?> But the problem is that the script is echoing alway first row username.....
-
Thanks cyberRobot and all others who helped me via this... now its working while($row = mysql_fetch_assoc($result)) { $categories[$row['sub_cat_id']]['subcat'] = array('name' => $row['sub_cat_name']); $categories[$row['sub_cat_id']]['topics'][$row['id']] = array('name' => $row['topic_title']); } foreach($categories as $sub_cat_id => $row): ?> <?php echo $row['subcat']['name']."<br>"; ?> <?php foreach($row['topics'] as $sub_id => $sub_row): ?> <?php echo $sub_row['name']."<br>"; ?> <?php endforeach; ?> <?php endforeach; } ?>
-
OK.... GOT IT... foreach($categories as $sub_cat_id => $row): ?> <?php echo $row['name']."<br>"; ?> <?php foreach($row['topics'] as $sub_id => $sub_row): ?> <?php echo $sub_row['name']."<br>"; ?> <?php endforeach; ?> <br> <?php endforeach; } ?> This line <?php echo $row['name']."<br>"; ?> should be <?php echo $row['subcat']['name']."<br>"; ?> Thanks neil.johnson
-
Okay When i run the code below..... Its showing category name as well <?php $categories = array(); $result = mysql_query("SELECT c.cat_id, c.cat_name, s.sub_cat_id, s.sub_cat_name FROM $category c INNER JOIN $sub_category s ON(c.cat_id=s.category_id) ORDER BY c.cat_name ASC, s.sub_cat_name ASC"); while($row = mysql_fetch_assoc($result)) { $categories[$row['cat_id']]['cat'] = array('name' => $row['cat_name']); $categories[$row['cat_id']]['subcats'][$row['sub_cat_id']] = array('name' => $row['sub_cat_name']); } print "<pre>"; print_r($categories); print "</pre>"; exit(); ?> But when i run the code below...... i get error Notice: Undefined index: name in C:\xampp\htdocs\demo\index.php on line 21 This is line 21 <h4><?php echo $row['name']; ?></h4> <?php $categories = array(); $result = mysql_query("SELECT c.cat_id, c.cat_name, s.sub_cat_id, s.sub_cat_name FROM $category c INNER JOIN $sub_category s ON(c.cat_id=s.category_id) ORDER BY c.cat_name ASC, s.sub_cat_name ASC"); while($row = mysql_fetch_assoc($result)) { $categories[$row['cat_id']]['cat'] = array('name' => $row['cat_name']); $categories[$row['cat_id']]['subcats'][$row['sub_cat_id']] = array('name' => $row['sub_cat_name']); } foreach($categories as $cat_id => $row): ?> <h4><?php echo $row['name']; ?></h4> <ul> <?php foreach($row['subcats'] as $sub_cat_id => $sub_row): ?> <li><?php echo $sub_row['name']; ?></li> <?php endforeach; ?> </ul> <?php endforeach; ?>
-
cyberRobot Hi, I tried as you said.... But still displaying only one topic title....... <?php if (isset($_GET["datatb"]) AND isset($_GET["cat_id"])){ $datatb = $_GET["datatb"]; $cat_id = $_GET["cat_id"]; $categories = array(); $result = mysql_query("SELECT s.sub_cat_id, s.sub_cat_name, t.sub_id, t.topic_title FROM $sub_category s INNER JOIN $datatb t ON(s.sub_cat_id=t.sub_id)"); while($row = mysql_fetch_assoc($result)) { if(!isset($categories[$row['sub_cat_id']])) { $categories[$row['sub_cat_id']] = array('name' => $row['sub_cat_name']); } $categories[$row['sub_cat_id']]['topics'][$row['sub_id']] = array('name' => $row['topic_title']); } foreach($categories as $sub_cat_id => $row): ?> <?php echo "<green>".$row['name']."</green> <br>"; ?> <?php foreach($row['topics'] as $sub_id => $sub_row): ?> <?php echo $sub_row['name']."<br><br>"; ?> <?php endforeach; ?> <?php endforeach; } ?>
-
its displaying same........ only one topic under each subcategory
-
Hard to understand where to add this print '<pre>' . print_r($categories, true) . '</pre>'; Here is the code i am using.... <?php if (isset($_GET["datatb"]) AND isset($_GET["cat_id"])){ $datatb = $_GET["datatb"]; $cat_id = $_GET["cat_id"]; $categories = array(); $result = mysql_query("SELECT s.sub_cat_id, s.sub_cat_name, t.sub_id, t.topic_title FROM $sub_category s INNER JOIN $datatb t ON(s.sub_cat_id=t.sub_id)"); while($row = mysql_fetch_assoc($result)) { $categories[$row['sub_cat_id']] = array('name' => $row['sub_cat_name']); $categories[$row['sub_cat_id']]['topics'][$row['sub_id']] = array('name' => $row['topic_title']); } foreach($categories as $sub_cat_id => $row): ?> <?php echo "<green>".$row['name']."</green> <br>"; ?> <?php foreach($row['topics'] as $sub_id => $sub_row): echo $sub_row['name']."<br><br>"; endforeach; ?> <?php endforeach; } ?> Can you kindly edit it....
-
This is how my tables look like subcategory sub_cat_id int auto_increment primary key, sub_cat_name varchar(500), category_id int(11) $datatb id int auto_increment primary key, topic_title mediumtext, topic_detail mediumtext, added_date date, sub_id int(11) => (sub_cat_id from subcategory table)
-
I think overwriting is not the problem...... Here you see this image The problem is that LOOP and Array subcategory have more topics. Its showing only 1st topic and not all
-
OK.... Will be waiting
-
Sorry that i started this topic again......... dalecosp can you please edit the code which i posted and make it fine so that it work.... Please.............
-
ok.. i changed it but still showing only 1 topic under subcategory list <?php if (isset($_GET["datatb"]) AND isset($_GET["cat_id"])){ $datatb = $_GET["datatb"]; $cat_id = $_GET["cat_id"]; $categories = array(); $result = mysql_query("SELECT s.sub_cat_id, s.sub_cat_name, t.sub_id, t.topic_title FROM $sub_category s INNER JOIN $datatb t ON(s.sub_cat_id=t.sub_id)"); while($row = mysql_fetch_assoc($result)) { $categories[$row['sub_cat_id']] = array('name' => $row['sub_cat_name']); $categories[$row['sub_cat_id']]['topics'][$row['sub_id']] = array('name' => $row['topic_title']); } foreach($categories as $sub_cat_id => $row): ?> <h4><?php echo $row['name']; ?></h4> <ul> <?php foreach($row['topics'] as $sub_id => $sub_row): ?> <li><?php echo $sub_row['name']; ?></li> <?php endforeach; ?> </ul> <?php endforeach; } ?>
-
Hi, The code is not able to loop topic_title on 2nd foreach loop..... Its looping the subcategory list but not topic_title. It shows only one topic_title under each subcategory Please help <?php if (isset($_GET["datatb"]) AND isset($_GET["cat_id"])){ $datatb = $_GET["datatb"]; $cat_id = $_GET["cat_id"]; $categories = array(); $result = mysql_query("SELECT s.sub_cat_id, s.sub_cat_name, t.sub_id, t.topic_title FROM $sub_category s INNER JOIN $datatb t ON(s.sub_cat_id=t.sub_id)"); while($row = mysql_fetch_assoc($result)) { $categories[$row['sub_cat_id']] = array('name' => $row['sub_cat_name']); $categories[$row['sub_cat_id']]['topics'][$row['sub_id']] = array('name' => $row['topic_title']); } foreach($categories as $sub_cat_id => $row): ?> <h4><?php echo $row['name']; ?></h4> <ul> <?php foreach($row['topics'] as $sub_cat_id => $sub_row): ?> <li><?php echo $sub_row['name']; ?></li> <?php endforeach; ?> </ul> <?php endforeach; } ?>
-
<?php $categories = array(); $result = mysql_query("SELECT c.cat_id, c.cat_name, s.sub_cat_id, s.sub_cat_name FROM $category c INNER JOIN $sub_category s ON(c.cat_id=s.category_id) ORDER BY c.cat_name ASC, s.sub_cat_name ASC"); while($row = mysql_fetch_assoc($result)) { $categories[$row['cat_id']]['cat'] = array('name' => $row['cat_name']); $categories[$row['cat_id']]['subcats'][$row['sub_cat_id']] = array('name' => $row['sub_cat_name']); } foreach($categories as $cat_id => $row): ?> <h4><?php echo $row['name']; ?></h4> <ul> <?php foreach($row['subcats'] as $sub_cat_id => $sub_row): ?> <li><?php echo $sub_row['name']; ?></li> <?php endforeach; ?> </ul> <?php endforeach; ?> This code is not displaying category name.. Notice: Undefined index: name in C:\xampp\htdocs\demo\index.php on line 20 When i remove ['cat'] from the line under $categories[$row['cat_id']]['cat'] = array('name' => $row['cat_name']); it shows category name but its not looping subcategory....... It just show 1 subcategory under it.
-
I tried it...... The code is doing different then what i want...... I have 3 table 1- category, 2- subcategory and 3- via $datatb variable. I am already showing category menu like this <a href='$_SERVER[PHP_SELF]?datatb=$row[cat_table]&cat_id=$row[cat_id]'>$row[cat_name]</a> Now am trying to make a function which will display subcategory name and under it the list of topics..... For example subcat name 1 (subcategory table) topic name 1 ($datatb table) topic name 2 topic name 3 topic name 4 subcat name 2 (subcategory table) topic name 1 ($datatb table) topic name 2 topic name 3
-
Thanks, i will try and will get back in 15mins
-
Hi, I am trying this task with the help of while loop but its not working.... Please check and correct me if this task can be done by while loop..... I have 3 tables 1- category, 2- subcategory and 3- via $datatb variable. In my index page am show categorys. I will pass category id and category table values by clicking on category link. <a href='$_SERVER[PHP_SELF]?datatb=$row[cat_table]&cat_id=$row[cat_id]'>$row[cat_name]</a> Now am trying to make a function which will display subcategory name and under it the list of topics..... For example subcat name 1 topic name 1 topic name 2 topic name 3 topic name 4 subcat name 2 topic name 1 topic name 2 topic name 3 My category table is like this cat_id int auto_increment primary key, cat_name varchar(255), cat_table varchar(255) My subcategory table is like this sub_cat_id int auto_increment primary key, sub_cat_name varchar(500), category_id int(11) My $datatb table is like this id int auto_increment primary key, topic_title mediumtext, topic_detail mediumtext, added_date date, sub_id int(11) This function am trying is this function subcat_nav(){ global $sub_category; if (isset ($_GET["datatb"])){ $datatb = $_GET["datatb"]; $cat_id = $_GET["cat_id"]; $sql1 = mysql_query("SELECT * FROM $sub_category WHERE category_id = '$cat_id'") or die(mysql_error()); while ($row1 = mysql_fetch_array($sql1)){ $sql2 = mysql_query("SELECT * FROM $datatb WHERE sub_id = '12'") or die(mysql_error()); while ($row2 = mysql_fetch_array($sql2)){ echo "$row1[sub_cat_name] <br>"; echo "$row2[topic_title] <br>"; }}}}
-
thanks I was just trying to put all PHP code in one function file.... So that when i redesign my site layout later.... i don't see many php codes Thanks again
-
Thanks for quick reply.... am leaning PHP and were doing some experiments
-
I want to call display function..... function admin(){ global $admin; function display($display){ $sql = mysql_query("SELECT * FROM $admin") or die (mysql_error()); $result = mysql_fetch_array($sql); echo $result["$display"]; } } I tried to call like this <?php display($username) ?> But its not working
-
Is there any way through which i can test mysql codes..... for example something like this but on my localhost http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_union
-
That was it Thanks to all who helped me