Jump to content

Datagrid In Php


assassin87

Recommended Posts

Hi Everyone, İ wanna ask you something. Now i have to create simple phonebook in PHP. I connected PHP and MySQL. I can insert data from PHP to SQL and i created a table. But i have to create a table like datagrid in C#. Because when I click to data i should delete or update data. And İ will put a search button because i must search peaople in my phonebook. Can anyone help me please ? http://tinypic.com/view.php?pic=9zn5ee&s=7 here is my sql table.

Link to comment
Share on other sites

For search, you can use this.

<!---for textbox --><input type="text" name="txtSearch"><!---for search button --><input type="button" value="Search" name="Search">

On the upper part of your page, put this code

<?phpif(isset($_POST['Search'])){   $product = stripslashes($_POST['txtSearch']);   if($product == ""){   header("Location:search.php");  }  else{   session_start();   $_SESSION['Search'] = $product;   header("Location:search.php");  }}?>

Then put this code on the upper part of your search page to get the value you have passed.

<?phpsession_start();$search = $_SESSION['Search'];?>

Lol, that's what my small mind can do. Maybe long and tricky but that is what I do it. Lol! Hope it helps =)

Link to comment
Share on other sites

What you want is a table printed out on the page in which users can edit anything in any cell and it automatically updates in the database? This would require Javascript, AJAX, PHP and MySQL.

Link to comment
Share on other sites

It's quite a complex application to build, that's all I can tell you. First, you need to generate the table. Add "click" events to each cell so that the text within it becomes a text input. Add a "change" event to the text input which will call a function that sends an AJAX request with the row identifier, field name and new data to a PHP script. On the server side, the PHP script will validate the data (make sure it's right for that database field) and use the row identifier and field name to update the data in the right location.

Link to comment
Share on other sites

Yeah i konow, i have learned PHP and SQL from W3 now i have to study JS and AJAX. I wanna ask one more question too. Now i have thoose codes. <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return$limit=10; // check for an empty string and display a message.if ($trimmed == "") { echo "<p>Kelime Giriniz...</p>"; exit; } // check for a search parameterif (!isset($var)) { echo "<p>Aranacak birsey yok!</p>"; exit; } //connect to your database ** EDIT REQUIRED HERE **mysql_connect("localhost","root","7687570"); //(host, username, password) //specify database ** EDIT REQUIRED HERE **mysql_select_db("arif") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from telefon_defteri where adi like \"%$trimmed%\" order by adi"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>pardon, Aradığınız kelime mevcut degil : "" . $trimmed . "" returned zero results</p>"; // google echo "<p><a href=\"http://www.google.com/search?q=" . $trimmed . "\" target=\"_blank\" title=\"Look up " . $trimmed . " on Google\">Click here</a> to try the search on google</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched forecho "<p>Aradiginiz kelime: "" . $var . ""</p>"; // begin to show results setecho "Results";$count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["adi"]; echo "$count.) $title" ; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> and after the search i want to see all datas not just ["adi"] i have 6 column in my database how can i bring all that datas.

Link to comment
Share on other sites

Just use all the columns. If you know their names, you can use them.

$field1 = $row['field1'];$field2 = $row['field2'];$field3 = $row['field3'];$field4 = $row['field4'];

Link to comment
Share on other sites

I don't want to take my job beyond the forums.If you can put a test page online and link to it from here that would be helpful. You can use fake data for the example page.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...