Jump to content

Peuplarchie

Members
  • Posts

    107
  • Joined

  • Last visited

    Never

Everything posted by Peuplarchie

  1. hahaha... I'm adding my development so if another have the same issue he can see. If.... This way also it gives more info on my issue, i guess. And it shows that I'm working on it...
  2. Getting closer... $sql1= 'SHOW TABLES FROM ' .$db .' LIKE '.$tname; $res1= mysql_query($sql1) OR die('Query 1 error:<br />' .mysql_error()); echo '<table border=1 cellpadding=1 cellspacing=0 width="90%">'; while ( $row= mysql_fetch_row($res1) ) { echo '<tr>'; echo '<td valign="top" align="center">' .$tname. '</td>'; echo '<td>'; $sql2= 'SHOW CREATE TABLE ' .$tname; $res2= mysql_query($sql2) OR die('Query 2 error:<br />' .mysql_error()); while ( $table_def= mysql_fetch_row($res2) ) { for ($i=1; $i<count($table_def); $i++) { echo '<pre>' .$table_def[$i]. '</pre>'; } } echo '</tr>'; } echo '</table>';
  3. Good day all, I'm working on a thing which lets the member create, edit, delet it's own table and data. I have a form in a table which list the table data, this form should add a row. Here is it's code : $tid = $_GET['id']; $tname = $_GET['tname']; $con = mysql_connect($server, $login, $password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($db, $con); $query = "SELECT * FROM $tname"; $resultv = mysql_query($query); if (($resultv)||(mysql_errno == 0)) { echo "<table width='100%' border=\"1\">\n"; echo "<tr>"; echo "<td align='center'><b>Options</b></td>"; if (mysql_num_rows($resultv)>0) { //loop thru the field names to print the correct headers $i = 0; while ($i < mysql_num_fields($resultv)) { echo "<th>". mysql_field_name($resultv, $i) . " <a href=\"tableau.php?act=delcol&opt=tableau&tname=".$tname."&cname=".mysql_field_name($resultv, $i)."\" title=\"DELETE COLUMN : ". mysql_field_name($resultv, $i) . "\"><img src=\"Images/stock_delete-column.png\" align=\"bottom\"></a></th>\n"; $i++; } echo "</tr>"; echo "<tr><form name=\"formadd\" method=\"post\" action=\"tableau.php?add=row\">\n"; //loop thru the field names to print the correct headers $i = 0; echo "<td align='center'><input type=\"submit\" value=\"Ajouter\"></td>"; while ($i < mysql_num_fields($resultv)) { echo "<td align='center'><input type=\"text\" name=\"". mysql_field_name($resultv, $i) . "\"</td>\n"; $i++; } echo "</form></tr>\n"; //display the data while ($rowv = mysql_fetch_array($resultv,MYSQL_ASSOC)) { echo "<tr><td><br></td>\n"; foreach ($rowv as $data) { if ($data == "") { echo "<td align='center'><br></td>\n"; }else{ echo "<td align='center'>". $data . "</td>\n"; } } } }else{ echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>\n"; } echo "</table>"; }else{ echo "Error in running query :". mysql_error(); } My issue is to receive the data and insert it in the database. I have know clue how to put the POSTs into variable so I can Insert it in the query.. Can somebody help me ? Take care !
  4. Impressive, here is what I come back with from before your post. how to implement it with a foreach loop. Let says instead I use index 0 to give me the whole piece and I replace the whole string with anther with the "number" index 1 with the formated html. See code preg_match_all('/\*&([a-z0-9]+)&\*/i',$tache,$out, PREG_SET_ORDER); echo $out[0][0] . ", " . $out[1][0] . ", " . $out[2][0] . ", " . $out[3][0] . ", " . $out[4][0] . "\n"; $i = 0; foreach ($out[$i][0] as &$value) { $value = str_replace("*&","<div class=\"progress-containers\"><div style=\"width:",$value); $value = str_replace("&*","%\">$value[$i][1]</div></div>",$value); $i++; }
  5. Good day to you all, I'm looking for a way to retrieve the text in between *& &* and put it's content into a $var. for each occurrence with in a string. $occu[0] = "dsfsdf"; $occu[1] = "10"; $occu[2] = "10sct"; Is there a way to do this ? I know how to do it but not recusively. function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } $parsed = get_string_between($tache, "*&", "&*"); $tache = str_replace("*&","<div class=\"progress-containers\"><div style=\"width:",$tache); $tache = str_replace("&*","%\">$parsed</div></div>",$tache); Can somebody can give me a tips ?
  6. Good day to everybody ! I'm working on a small to-do list. I have created a text editor to add no todo to it. Here is the code : <script> //modified version of http://www.webmasterworld.com/forum91/4686.htm //myField accepts an object reference, myValue accepts the text string to add function insertAtCursor(myField, myValue) { //fixed scroll position textAreaScrollPosition = myField.scrollTop; //IE support if (document.selection) { myField.focus(); //in effect we are creating a text range with zero //length at the cursor location and replacing it //with myValue sel = document.selection.createRange(); sel.text = myValue; //Mozilla/Firefox/Netscape 7+ support } else if (myField.selectionStart || myField.selectionStart == '0') { myField.focus(); //Here we get the start and end points of the //selection. Then we create substrings up to the //start of the selection and from the end point //of the selection to the end of the field value. //Then we concatenate the first substring, myValue, //and the second substring to get the new value. var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); myField.setSelectionRange(endPos+myValue.length, endPos+myValue.length); } else { myField.value += myValue; } //fixed scroll position myField.scrollTop = textAreaScrollPosition; } </script> <form action="ajoutage.php" method="post" name="ajout" id="ajout"> <table cellpadding="0" cellspacing"0" border="0"> <input type="hidden" name="sujet" value="<?PHP echo $_GET['sujet']; ?>"/> <input type="hidden" name="categorie" value="<?PHP echo $_GET['categorie']; ?>"/> <tr><td width="85px">Titre : </td><td><input type="text" name="titre"/></td> <td></td> <td>Ajouteur : </td><td align="right"><input type="text" name="ajouteur" value="<?PHP echo $qui; ?>"/></td> </tr> <tr><td width="85px">Sujet : </td><td><input type="text" name="sujet"/></td> <td></td> <td>Status : </td><td align="right"><input type="text" name="status"/></td> </tr> <tr><td width="85px">Catégorie : </td><td><input type="text" name="categorie"/></td> <td></td> <td>Niveau : </td><td align="right"><input type="text" name="niveau"/></td> </tr> <tr><td colspan="5">Tâche : <a href="#" onClick="insertAtCursor(document.ajout.tache, '<tr><td></td>\n<td>*&0&*</td>\n</tr>\n')">Progress</a> | <a href="#" onClick="insertAtCursor(document.ajout.tache, '<tr colspan=3>\n<td></td>\n</tr>\n')">Pleinne</a> | <br><textarea name="tache" id="tache" cols="70" rows="20" wrap="off" spellcheck="false"></textarea></td> </tr> <tr><td colspan="5"><input type="submit" value="Ajouter"/></td></tr> </table> </form> It works very fine, as you can see there is to links that is use to add some text in the textarea, where ever the cursor is. Where it starts : I have also created another form to modify the todo's once they are created. The only problem here is that my 2 links for adding text to the textarea don't work at all, they do nothng, no error shown, no text added. Here is the code use to modify the todos once created: <script type="text/javascript"> //modified version of http://www.webmasterworld.com/forum91/4686.htm //myField accepts an object reference, myValue accepts the text string to add function insertAtCursor(myField, myValue) { //fixed scroll position textAreaScrollPosition = myField.scrollTop; //IE support if (document.selection) { myField.focus(); //in effect we are creating a text range with zero //length at the cursor location and replacing it //with myValue sel = document.selection.createRange(); sel.text = myValue; //Mozilla/Firefox/Netscape 7+ support } else if (myField.selectionStart || myField.selectionStart == '0') { myField.focus(); //Here we get the start and end points of the //selection. Then we create substrings up to the //start of the selection and from the end point //of the selection to the end of the field value. //Then we concatenate the first substring, myValue, //and the second substring to get the new value. var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); myField.setSelectionRange(endPos+myValue.length, endPos+myValue.length); } else { myField.value += myValue; } //fixed scroll position myField.scrollTop = textAreaScrollPosition; } </script> <?php $con = mysql_connect("localhost","XXXXXX","XXXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("XXXXXX", $con); $id = $_GET['id']; $qui = $_GET['qui']; $sujet = $_GET['sujet']; $categorie = $_GET['categorie']; $result = mysql_query("SELECT * FROM todo where id='$id'"); while($row = mysql_fetch_array($result)) { echo " <form action=\"modifiage.php\" name=\"ajout\" id=\"ajout\" method=\"post\"> <table cellpadding=\"0\" cellspacing\"0\" border=\"0\"> <input type=\"hidden\" name=\"id\" value=\"" . $row['id'] . "\"/> <input type=\"hidden\" name=\"qui\" value=\"" . $row['ajouteur'] . "\"/> <input type=\"hidden\" name=\"sujet\" value=\"" . $row['sujet'] . "\"/> <input type=\"hidden\" name=\"categorie\" value=\"" . $row['categorie'] . "\"/> <tr><td width=\"85px\">Titre : </td><td><input type=\"text\" name=\"titre\" value=\"" . $row['titre'] . "\"/></td> <td></td> <td>Ajouteur : </td><td align=\"right\"><input type=\"text\" name=\"ajouteur\" value=\"" . $row['ajouteur'] . "\"/></td> </tr> <tr><td width=\"85px\">Sujet : </td><td><input type=\"text\" name=\"sujet\" value=\"" . $row['sujet'] . "\"/></td> <td></td> <td>Status : </td><td align=\"right\"><input type=\"text\" name=\"status\" value=\"" . $row['status'] . "\"/></td> </tr> <tr><td width=\"85px\">Catégorie : </td><td><input type=\"text\" name=\"categorie\" value=\"" . $row['categorie'] . "\"/></td> <td></td> <td>Niveau : </td><td align=\"right\"><input type=\"text\" name=\"niveau\" value=\"" . $row['niveau'] . "\"/></td> </tr> <tr> "; $tache = $row['tache']; $tache = str_replace("<div class=\"progress-containers\"><div style=\"width:","*&",$tache); $tache = str_replace("%\"><br></div></div>","&*",$tache); $onmouse = '<tr onMouseOver="this.className=**highlight**" onMouseOut="this.className=**normal**"><td>'; $tache = str_replace($onmouse,"<tr><td>",$tache); echo " <td colspan=\"5\">Tâche : <a href=\"#\" onClick=\"insertAtCursor(document.ajout.tache, '<tr><td></td>\n<td>*&0&*</td>\n</tr>\n')\">Progress</a> | <a href=\"#\" onClick=\"insertAtCursor(document.ajout.tache, '<tr colspan=3>\n<td></td>\n</tr>\n')\">Pleinne</a> | <br><textarea name=\"tache\" id=\"tache\" cols=\"70\" rows=\"20\" wrap=\"off\" spellcheck=\"false\">" . $tache . "</textarea></td> </tr> <tr><td colspan=\"5\"><input type=\"submit\" value=\"Modifier\"/></td> </tr> </table> </form> "; } mysql_close($con); ?>
  7. Good day to you all, I new in php MySQL classes and I have found a nice model. (See code 1 later) I would like to add to it but I'm not sure how, can somebody help me, any help is good to learn ! Code 1 (Model Class) <?php # Name: Database.class.php # File Description: MySQL Class to allow easy and clean access to common mysql commands # Author: ricocheting # Web: http://www.ricocheting.com/ # Update: 2010-05-08 # Version: 3.1.3 # Copyright 2003 ricocheting.com /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ //require("config.inc.php"); //$db = Database::obtain(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE); //$db = Database::obtain(); ################################################################################################### ################################################################################################### ################################################################################################### class Database{ // debug flag for showing error messages public $debug = true; // Store the single instance of Database private static $instance; private $server = ""; //database server private $user = ""; //database login name private $pass = ""; //database login password private $database = ""; //database name private $error = ""; ####################### //number of rows affected by SQL query public $affected_rows = 0; private $link_id = 0; private $query_id = 0; #-############################################# # desc: constructor private function __construct($server=null, $user=null, $pass=null, $database=null){ // error catching if not passed in if($server==null || $user==null || $pass==null || $database==null){ $this->oops("Database information must be passed in when the object is first created."); } $this->server=$server; $this->user=$user; $this->pass=$pass; $this->database=$database; }#-#constructor() #-############################################# # desc: singleton declaration public static function obtain($server=null, $user=null, $pass=null, $database=null){ if (!self::$instance){ self::$instance = new Database($server, $user, $pass, $database); } return self::$instance; }#-#obtain() #-############################################# # desc: connect and select database using vars above # Param: $new_link can force connect() to open a new link, even if mysql_connect() was called before with the same parameters public function connect($new_link=false){ $this->link_id=@mysql_connect($this->server,$this->user,$this->pass,$new_link); if (!$this->link_id){//open failed $this->oops("Could not connect to server: <b>$this->server</b>."); } if(!@mysql_select_db($this->database, $this->link_id)){//no database $this->oops("Could not open database: <b>$this->database</b>."); } // unset the data so it can't be dumped $this->server=''; $this->user=''; $this->pass=''; $this->database=''; }#-#connect() #-############################################# # desc: close the connection public function close(){ if(!@mysql_close($this->link_id)){ $this->oops("Connection close failed."); } }#-#close() #-############################################# # Desc: escapes characters to be mysql ready # Param: string # returns: string public function escape($string){ if(get_magic_quotes_runtime()) $string = stripslashes($string); return @mysql_real_escape_string($string,$this->link_id); }#-#escape() #-############################################# # Desc: executes SQL query to an open connection # Param: (MySQL query) to execute # returns: (query_id) for fetching results etc public function query($sql){ // do query $this->query_id = @mysql_query($sql, $this->link_id); if (!$this->query_id){ $this->oops("<b>MySQL Query fail:</b> $sql"); return 0; } $this->affected_rows = @mysql_affected_rows($this->link_id); return $this->query_id; }#-#query() #-############################################# # desc: does a query, fetches the first row only, frees resultset # param: (MySQL query) the query to run on server # returns: array of fetched results public function query_first($query_string){ $query_id = $this->query($query_string); $out = $this->fetch($query_id); $this->free_result($query_id); return $out; }#-#query_first() #-############################################# # desc: fetches and returns results one line at a time # param: query_id for mysql run. if none specified, last used # return: (array) fetched record(s) public function fetch($query_id=-1){ // retrieve row if ($query_id!=-1){ $this->query_id=$query_id; } if (isset($this->query_id)){ $record = @mysql_fetch_assoc($this->query_id); }else{ $this->oops("Invalid query_id: <b>$this->query_id</b>. Records could not be fetched."); } return $record; }#-#fetch() #-############################################# # desc: returns all the results (not one row) # param: (MySQL query) the query to run on server # returns: assoc array of ALL fetched results public function fetch_array($sql){ $query_id = $this->query($sql); $out = array(); while ($row = $this->fetch($query_id)){ $out[] = $row; } $this->free_result($query_id); return $out; }#-#fetch_array() #-############################################# # desc: does an update query with an array # param: table, assoc array with data (not escaped), where condition (optional. if none given, all records updated) # returns: (query_id) for fetching results etc public function update($table, $data, $where='1'){ $q="UPDATE `$table` SET "; foreach($data as $key=>$val){ if(strtolower($val)=='null') $q.= "`$key` = NULL, "; elseif(strtolower($val)=='now()') $q.= "`$key` = NOW(), "; elseif(preg_match("/^increment\((\-?\d+)\)$/i",$val,$m)) $q.= "`$key` = `$key` + $m[1], "; else $q.= "`$key`='".$this->escape($val)."', "; } $q = rtrim($q, ', ') . ' WHERE '.$where.';'; return $this->query($q); }#-#update() #-############################################# # desc: Add column # param: # returns: public function alter($table, $data){ $q="ALTER `$table` ADD COLUMN "; foreach($data as $key=>$val){ if(strtolower($val)=='null') $q.= "`$key` = NULL, "; elseif(strtolower($val)=='now()') $q.= "`$key` = NOW(), "; elseif(preg_match("/^increment\((\-?\d+)\)$/i",$val,$m)) $q.= "`$key` = `$key` + $m[1], "; else $q.= "`$key`='".$this->escape($val)."', "; } $q = rtrim($q, ', ') . ' WHERE '.$where.';'; return $this->query($q); }#-#alter() #-############################################# # desc: Duplicate row # param: # returns: #-#duplicate() #-############################################# # desc: does an insert query with an array # param: table, assoc array with data (not escaped) # returns: id of inserted record, false if error public function insert($table, $data){ $q="INSERT INTO `$table` "; $v=''; $n=''; foreach($data as $key=>$val){ $n.="`$key`, "; if(strtolower($val)=='null') $v.="NULL, "; elseif(strtolower($val)=='now()') $v.="NOW(), "; else $v.= "'".$this->escape($val)."', "; } $q .= "(". rtrim($n, ', ') .") VALUES (". rtrim($v, ', ') .");"; if($this->query($q)){ return mysql_insert_id($this->link_id); } else return false; }#-#insert() #-############################################# # desc: frees the resultset # param: query_id for mysql run. if none specified, last used private function free_result($query_id=-1){ if ($query_id!=-1){ $this->query_id=$query_id; } if($this->query_id!=0 && !@mysql_free_result($this->query_id)){ $this->oops("Result ID: <b>$this->query_id</b> could not be freed."); } }#-#free_result() #-############################################# # desc: throw an error message # param: [optional] any custom error to display private function oops($msg=''){ if(!empty($this->link_id)){ $this->error = mysql_error($this->link_id); } else{ $this->error = mysql_error(); $msg="<b>WARNING:</b> No link_id found. Likely not be connected to database.<br />$msg"; } // if no debug, done here if(!$this->debug) return; ?> <table align="center" border="1" cellspacing="0" style="background:white;color:black;width:80%;"> <tr><th colspan=2>Database Error</th></tr> <tr><td align="right" valign="top">Message:</td><td><?php echo $msg; ?></td></tr> <?php if(!empty($this->error)) echo '<tr><td align="right" valign="top" nowrap>MySQL Error:</td><td>'.$this->error.'</td></tr>'; ?> <tr><td align="right">Date:</td><td><?php echo date("l, F j, Y \a\\t g:i:s A"); ?></td></tr> <?php if(!empty($_SERVER['REQUEST_URI'])) echo '<tr><td align="right">Script:</td><td><a href="'.$_SERVER['REQUEST_URI'].'">'.$_SERVER['REQUEST_URI'].'</a></td></tr>'; ?> <?php if(!empty($_SERVER['HTTP_REFERER'])) echo '<tr><td align="right">Referer:</td><td><a href="'.$_SERVER['HTTP_REFERER'].'">'.$_SERVER['HTTP_REFERER'].'</a></td></tr>'; ?> </table> <?php }#-#oops() }//CLASS Database ################################################################################################### ?> Now I'm trying to add a function that would let me add column. Please look at function alter in the code1 and if you can lead me tomy understanding. Thanks!
  8. Good day to you all, I'm trying to read a directory and for each file add : path, name, ext, width and height to my database. Right now the only thing I had succeed in to list the image directory. I have tried out to add it to the database but no reaction, nothing is added to the db, no error ? Here is my code: <?php // Connect to database $con = mysql_connect("localhost","111",111"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("images", $con); $imgdir = 'Images/'; // the directory, where your images are stored $realimgdir = "Images/"; $allowed_types = array('png','jpg','jpeg','gif','bmp'); // list of filetypes you want to show $dimg = opendir($imgdir); while($imgfile = readdir($dimg)) { if(in_array(strtolower(substr($imgfile,-3)),$allowed_types)) { $a_img[] = $imgfile; sort($a_img); reset ($a_img); } } $totimg = count($a_img); // total image number for($x=0; $x < $totimg; $x++) { $size = getimagesize($imgdir.'/'.$a_img[$x]); // do whatever $halfwidth = ceil($size[0]/2); $halfheight = ceil($size[1]/2); $rid = $realimgdir; $fname = substr($a_img[$x],0, -4); $extens = substr($a_img[$x], -3); $iwidth = $size[0]; $iheight = $size[1]; mysql_query("INSERT INTO gallery (id, path, name, ext, width, height) VALUES ('$rid', '$fname', '$extens', '$iwidth', '$iheight'"); echo '<tr title="'.$a_img[$x].'" onMouseOver="this.className=\'highlight\'" onMouseOut="this.className=\'normal\'"></td><td>'.$realimgdir.'</td><td>'.substr($a_img[$x],0, -4).'</td><td style="text-align:center;"> '.substr($a_img[$x], -3).' </td><td style="text-align:center;"> '.$size[0].' </td><td style="text-align:center;"> '.$size[1].'</td></tr>'; } ?> </table> Somebody have an idea
  9. Yeah that is what I want to do, but I dont know how to code it, can you help me on this ?
  10. Good day to you all, I'm working on a MySQL database production area. I don't yet have access to my SSH connect ion and I'm trying to not use it since it's for a project orther that my regular. I have my adding , deleting and editing script all in separate php pages. For each table that I want to be able to play with I have to rename and edit thos pages acordingly. Is there a way that I can make only a single adding, deleting and editing page work for each table in all database ? What is all the people do ?, that is the part I don't catch. Here is my pages: notes.php <?PHP //check if the starting row variable was passed in the URL or not if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) { //we give the value of the starting row to 0 because nothing was found in URL $startrow = 0; //otherwise we take the value from the URL } else { $startrow = (int)$_GET['startrow']; } mysql_connect("localhost","USER","PASSWORD");//database connection mysql_select_db("DB"); $order = mysql_query("SELECT * FROM Notes"); $num_rows = mysql_num_rows($order); // Sort Process debut $ord = (isset($_GET['ord']) && ($_GET['ord'] == 'ASC' || $_GET['ord'] == 'DESC') ? $_GET['ord'] : 'ASC'); // sets 'desc' as default $link = ($ord == 'ASC' ? 'DESC' : 'ASC'); if(empty($_GET['coll'])) { $_GET['coll'] = "priorite"; } $col = mysql_real_escape_string(trim($_GET['coll'])); // Sort Process fin //General mysql query debut $order = "SELECT * FROM Notes ORDER BY `$col` $ord LIMIT $startrow, 30"; if($order == false) { user_error(mysql_error() . "<br />\n$order"); die("SQL error"); } //General mysql query fin // Headers $result = mysql_query($order); for ($i = 0; $i < mysql_num_fields($result); $i++) { if (mysql_field_name($result, $i) == "id"){ print "<th id=\"title\" style=\"color:#FF0000;\"><a href=\"".$_SERVER['PHP_SELF']."?coll=".mysql_field_name($result, $i)."&ord=".$link."&time=".date("hisu")."\" title=\"Sort by : ".mysql_field_name($result, $i)."\" style=\"color:#000000;\">ID</a></th>\n"; }else{ print "<th id=\"title\"><a href=\"".$_SERVER['PHP_SELF']."?coll=".mysql_field_name($result, $i)."&ord=".$link."&time=".date("hisu")."\" title=\"Sort by : ".mysql_field_name($result, $i)."\"style=\"color:#000000;\">".mysql_field_name($result, $i)."</a></th>\n"; } } echo "</tr>"; // Headers fin // Form Debut echo "<tr><form method=\"post\" name=\"action\" action=\"add_row_notes.php\">"; print "<td id=\"submit\"><input type=\"submit\" id=\"envoyer\" value=\" \"></td>\n"; for ($i = 0; $i < mysql_num_fields($result); $i++) { if (mysql_field_name($result, $i) == "modif"){ print "<td id=\"submit\"><input id=\"submitt\" type=\"text\" size=\"10\" name=\"".mysql_field_name($result, $i)."\" value=\"".date('Y-m-d G:i:s')."\"></td>\n"; }else{ if (mysql_field_name($result, $i) == "note"){ print "<td id=\"submit\"><input id=\"submitt\" type=\"text\" size=\"50\" name=\"".mysql_field_name($result, $i)."\" value=\"".$_SESSION[mysql_field_name($result, $i)]."\"></td>\n"; }else{ if (mysql_field_name($result, $i) == "titre"){ print "<td id=\"submit\"><input id=\"submitt\" type=\"text\" size=\"30\" name=\"".mysql_field_name($result, $i)."\" value=\"".$_SESSION[mysql_field_name($result, $i)]."\"></td>\n"; }else{ if (mysql_field_name($result, $i) == "priorite"){ print "<td id=\"submit\"><select name=\"".mysql_field_name($result, $i)."\"><option value=\"1-Urgent\" selected>1-Urgent</option><option value=\"2-Normal\">2-Normal</option><option value=\"3-Eventuellement\">3-Eventuellement</option><option value=\"4-Autre\">4-Autre</option></select></td>\n"; }else{ if (mysql_field_name($result, $i) == "status"){ print "<td id=\"submit\"><select name=\"".mysql_field_name($result, $i)."\"><option value=\"Ouvert\" selected>Ouvert</option><option value=\"Attente_Discussion\">Attente Discussion</option><option value=\"Fermer\">Fermer</option></select></td>\n"; }else{ if (mysql_field_name($result, $i) == "categorie"){ print "<td id=\"submit\">"; print "<select name=\"".mysql_field_name($result, $i)."\">"; print "<option value=\"**-Franck\" selected>**-test</option>"; print "<option value=\"**-Rocky\" selected>**-test2</option>"; print "<option value=\"Vivants\" selected>Vivants</option>"; print "<option value=\"Inspirations\">Inspirations</option>"; print "<option value=\"Connaissances\">Connaissances</option>"; print "<option value=\"Ensemble\">Ensemble</option>"; print "<option value=\"Outils\">Outils</option>"; print "</select></td>\n"; }else{ print "<td id=\"submit\"><input id=\"submitt\" type=\"text\" size=\"1\" name=\"".mysql_field_name($result, $i)."\" value=\"".$_SESSION[mysql_field_name($result, $i)]."\"></td>\n"; } } } } } } } echo "</form></tr>"; // Headers Fin //Grid $result = mysql_query($order); $i = 1; while(($data = mysql_fetch_row($result))!== false){ $i++; if ($data[1] == ''){$data[1] = "<br>";}else{} if ($data[2] == ''){$data[2] = "<br>";}else{} if ($data[3] == ''){$data[3] = "<br>";}else{} if ($data[4] == ''){$data[4] = "<br>";}else{} if ($data[5] == ''){$data[5] = "<br>";}else{} if ($data[5] == ''){$data[6] = "<br>";}else{} if ($data[5] == ''){$data[7] = "<br>";}else{} echo("<tr style=\"border:0px;\" onMouseOver=\"this.className='highlight'\" onMouseOut=\"this.className='normal'\"> <td id=\"fields".($i & 1)."\"> <a href=\"delete_row_notes.php?id=" . $data['0'] . "\" title=\"DELETE : Row ID #:" . $data['0'] . "\"> <img src=\"Template/Images/delete.png\" border=\"0\"/></a> <a href=\"editor_row.php?id=".$data['0']."\" title=\"Edit : Row ID #:".$data['0']."\" onclick=\"load('editor_row.php?id=".$data['0']."','".$data['0']."');return false;\"> <img src=\"Template/Images/edit_icon.png\" border=\"0\"/></a> </td> <td id=\"fields".($i & 1)."\">". $data[0]."</td> <td id=\"fields".($i & 1)."\">". $data[1]."</td> <td id=\"fields".($i & 1)."\">". $data[2]."</td> <td id=\"fields".($i & 1)."\">". $data[3]."</td> <td id=\"fields".($i & 1)."\">". $data[4]."</td> <td id=\"fields".($i & 1)."\">". $data[5]."</td> <td id=\"fields".($i & 1)."\">". $data[6]."</td> </tr><tr><td colspan=\"8\" id=\"".$data['0']."\"></td></tr>"); } // Grid fin //PREV & NEXT debut echo "<tr><td colspan=\"8\" align=\"center\" id=\"listpage\">"; //only print a "Previous" link if a "Next" was clicked $prev = $startrow - 30; if ($prev >= 0) echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'" title="Précedante ('.$prev.'/'.$startrow.')" style=\"color:#FFFFFF;\"> ('.$prev.'/'.$startrow.') Précedante</a> '; $next = $startrow+30; echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+30).'" title="Prochaine ('.$startrow.'/'.$next.')" style=\"color:#FFFFFF;\">Prochaine <font style="color:#003300">(</font>'.$startrow.'<font style="color:#003300">-</font>'.$next.'<font style="color:#003300"> / </font>'.$num_rows .'<font style="color:#003300">)</font></a>'; $prev = $startrow - 30; echo "</td></tr>"; //PREV & NEXT fin echo "</table></td></tr></table>"; ?> Add_row.php <?PHP $id = $_POST['id']; $_SESSION['id'] = $_POST['id']; $modif = $_POST['modif']; $_SESSION['modif'] = $_POST['modif']; $priorite = $_POST['priorite']; $_SESSION['priorite'] = $_POST['priorite']; $status = $_POST['status']; $_SESSION['status'] = $_POST['status']; $categorie = $_POST['categorie']; $_SESSION['categorie'] = $_POST['categorie']; $titre = $_POST['titre']; $_SESSION['titre'] = $_POST['titre']; $note = $_POST['note']; $_SESSION['note'] = $_POST['note']; mysql_connect("localhost","USER","PASSWORD");//database connection mysql_select_db("DB"); //inserting data order $order = "INSERT INTO Notes (id, modif, priorite, status, categorie, titre, note) VALUES ('NULL', '$modif', '$priorite', '$status', '$categorie', '$titre', '$note')"; //declare in the order variable $result = mysql_query($order); //order executes if($result){ echo("<br>Input data is succeed"); } else{ echo("<br>Input data is fail"); } $time = date("hisu"); ?> <script language="javascript"><!-- location.replace("Notes.php?time=<?PHP echo $time; ?>") //--> </script> I won't put my deleting and editing script, but I have added my script for adding a row to the db so you can see more of what I mean. I hope you will understand my question. Thanks !
  11. Good day to you, I have added an options to my db production site which is to back up the table into csv file, see code below. Now I would like to be able to export to sql file, how would I do it without using phpMyadmin , I would like to use a function like the following. <?php $host = 'localhost'; $user = '....'; $pass = '....'; $db = '....'; $table = $_GET[table][tr][td]; $file = 'export'; $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error()); mysql_select_db($db) or die("Can not connect."); $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field']."; "; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= $rowr[$j]."; "; } $csv_output .= "\n"; } $filename = "Backup__".$table."__".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; echo "Exporting..."; ?> Thanks! [/td][/tr][/table]
  12. I know how to read, list files with glob, the part I don't know is how to put the result into the db, url or whole image.
  13. Good day to you all, I was looking into makeing a database of all my image and I was wondering if there is a way to read a recursive directory and store it into the database. I don't have a clue on how, even if I have search the web for a while. Thanks, take care and have a good one !
  14. yes it do. That is the part I don't understand.
  15. I tried the $row['id'] but it don't display anything.
  16. Good day to you all, I'm still learning the wicked database world and i found a piece of code which read and display a db table without me telling each colum totle and field name. Here is my code: ... if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // sending query $result = mysql_query("SELECT * FROM {$table}"); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); echo "<h1>Table: {$table}</h1>"; echo "<table border='0' id=\"table\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"><tr>"; echo "<td id=\"title\">options</td>"; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td id=\"title\">{$field->name}</td>"; } echo "</tr>\n"; // printing table rows $s = 0; while(($row = mysql_fetch_row($result)) !== false){ $s++; echo "<tr>"; echo "<td id=\"fields".($s & 1)."\"><a href=\"delete_table_row_db.php?id=" . $s[id]. "\" title=\"DELETE : Row ID #:" . $s[id] . "\"><img src=\"Template/Images/delete.png\" border=\"0\"/></a><INPUT TYPE=\"checkbox\" name=\"" . $row['id'] . "\"></td>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "<td id=\"fields".($s & 1)."\">$cell</td>"; echo "</tr>\n"; } mysql_free_result($result); In the part : <td id=\"fields".($s & 1)."\"><a href=\"delete_table_row_db.php?id=" . $s[id]. "\" title=\"DELETE : Row ID #:" . $s[id] . "\"><img src=\"Template/Images/delete.png\" border=\"0\"/></a><INPUT TYPE=\"checkbox\" name=\"" . $row['id'] . "\"></td>"; What i'm trying to do is to add options to the row, ex: delete, edit... My only problem is that I cannot find the var to put which would tell which row it is. Can somebody help me ? Thanks!
  17. how would I also variably give the order asc or desc ? mysql_select_db("peuplarc_sports", $con); $ord = $_GET['ord']; if(empty($_GET['coll'])) { die("No column received"); } $col = mysql_real_escape_string(trim($_GET['coll'])); $query = "SELECT * FROM NHL_GBG_PLAYERS ORDER BY $ord `$col`"; $result = mysql_query($query); if($result == false) { user_error(mysql_error() . "<br />\n$query"); die("SQL error"); }
  18. Good day to you all, I'm working on a script which would read a url var and sort mysql table by the variable, but I always get the errore that : Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in DB_API/sort_column.php on line 13 Can somebody help me fix my problem. I think it's the variable that is not use right in the MYSQL query ( $result = mysql_query("SELECT * FROM NHL_GBG_PLAYERS ORDER BY {$col}"); ) Here is my code : <?php $con = mysql_connect("localhost","sports","sports"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("sports", $con); $col = $_POST['coll']; $result = mysql_query("SELECT * FROM players ORDER BY {$col}"); while($row = mysql_fetch_array($result)) { echo "<div style=\"width:1090px; align-left:auto; margin-right:auto;\">"; echo "<div style=\"float:left; width:30px; border:1px solid #000000; \">" . $row['id'] . "</div>"; echo "<div style=\"float:left; width:100px; border:1px solid #cccccc;\">" . $row['date'] . "</div>"; echo "<div style=\"float:left; width:100px; border:1px solid #cccccc;\">" . $row['heure'] . "</div>"; echo "<div style=\"float:left; width:100px; border:1px solid #cccccc;\">" . $row['lieu'] . "</div>"; echo "<div style=\"float:left; width:100px; border:1px solid #cccccc;\">" . $row['assistance'] . "</div>"; echo "<div style=\"float:left; width:100px; border:1px solid #cccccc;\">" . $row['adversaire'] . "</div>"; echo "<div style=\"float:left; width:100px; border:1px solid #cccccc;\">" . $row['equipe'] . "</div>"; echo "<div style=\"float:left; width:100px; border:1px solid #cccccc;\">" . $row['nom'] . "</div>"; echo "<div style=\"float:left; width:20px; border:1px solid #cccccc;\">" . $row['b'] . "</div>"; echo "<div style=\"float:left; width:20px; border:1px solid #cccccc;\">" . $row['p'] . "</div>"; echo "<div style=\"float:left; width:40px; border:1px solid #cccccc;\">" . $row['pts'] . "</div>"; echo "<div style=\"float:left; width:20px; border:1px solid #cccccc;\">" . $row['l'] . "</div>"; echo "<div style=\"float:left; width:40px; border:1px solid #cccccc;\">" . $row['mdp'] . "</div>"; echo "<div style=\"float:left; width:30px; border:1px solid #cccccc;\">" . $row['bg'] . "</div>"; echo "<div style=\"float:left; width:30px; border:1px solid #cccccc;\">" . $row['be'] . "</div>"; echo "<div style=\"float:left; width:40px; border:1px solid #cccccc;\">" . $row['bea'] . "</div>"; echo "<div style=\"float:left; width:40px; border:1px solid #cccccc;\">" . $row['bed'] . "</div>"; echo "<div style=\"float:left; width:40px; border:1px solid #cccccc;\">" . $row['PM'] . "</div>"; echo "</div><br>"; } mysql_close($con); ?> Thanks!
  19. Good day to you all, I finally made the switch between txt based database to real database , i'm using mysql. I'm working on a table display and I cannot find a solution to 2 of my questions: 1. how can I make the first td of each row to have no border on the left as well as the last td of the row to have a right border ? 2. How can I auto generate the first field to so I can add my delete option ? Here is my code so far: <?php $db_host = 'localhost'; $db_user = 'peuplarc_sports'; $db_pwd = 'sports!123'; $database = 'peuplarc_sports'; $table = 'NHL_GBG_PLAYERS'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // sending query $result = mysql_query("SELECT * FROM {$table}"); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); echo "<h1>Table: {$table}</h1>"; echo "<table border='0' id=\"table\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"><tr>"; echo "<td id=\"title\">options</td>"; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td id=\"title\">{$field->name}</td>"; } echo "</tr>\n"; // printing table rows $s = 0; while(($row = mysql_fetch_row($result)) !== false){ $s++; echo "<tr>"; echo "<td id=\"fields".($s & 1)."\"><a href=\"delete_table_row_db.php?id=" . $row . "\" title=\"DELETE : Row ID #:" . $row . "\"><img src=\"Template/Images/delete.png\" border=\"0\"/></a><INPUT TYPE=\"checkbox\" name=\"" . $row['id'] . "\"></td>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "<td id=\"fields".($s & 1)."\">$cell</td>"; echo "</tr>\n"; } mysql_free_result($result); ?> Thank and have a great day !
  20. Good day to you all, I'm working on a flat file database login script. I have notice that once the user have input his/her username in the field what ever he/she put as password, as long as they put something in the field, matching or not, they are in. I'm sure I'm doing something wrong. Don't worries, I hide my flat file behind a httpassword file. Here is my code: <?php //sessions must be initialized prior to any output if output buffering if off session_start(); //the list of files containing passwords $files = array( "../../MurSec/FSC/memmob.txt", "../../MurSec/FSC/memmob.txt", "../../MurSec/FSC/memmob.txt" ); //if list of users not set create a new array if(!isset($_SESSION['users'])) $_SESSION['users'] = array(); if(isset($_POST['username']) && isset($_POST['password'])){ //need to remove slashes from POST if magic_quotes are on if(get_magic_quotes_gpc()){ $_POST['username'] = stripslashes($_POST['username']); $_POST['password'] = stripslashes($_POST['password']); } $userFound = false; //we need this to exit the loops foreach($files as $file){ //loop every file in the $files array if($fh = fopen($file, "r")){ while(!feof($fh) && !$userFound){ //while not the end of the current file or the user was not found list($username, $password, $url) = explode(",", fgets($fh,1024)); if(($username == $_POST['username']) && ($password = $_POST['password'])){ $_SESSION['username'] = $username; $_SESSION['present'] = true; $_SESSION['legal'] = true; $_SESSION['profile'] = $username.".txt"; array_push($_SESSION['users'], $username); //add the current user to the list of users header("Location: ".$url); $userFound = true; //confirm that the user was found // other session and log action } } } fclose($fh); //we need to use break to exit the foreach loop if the user is found in one of the files if($userFound) break; } else echo "Unable to open a required password file: $file"; } if(!$userFound) login('Wrong username or password.<br />'); } else { login(); } ?> <?php function login($response='Bienvenue, invité(e) !') { ?> <html> </head> </head> <body> <fieldset style="background-color:#cccccc;"> <legend><?=$response?></legend> <form action="" method="post"> <label for="nom">Membre :</label><input name="username" type="text" /><br> <label for="nom">Passe :</label><input name="password" type="password"><br> <br><center><input type="submit" value="Valider" /><br/></center> </form> </fieldset> </body> </html> <?php } ?> Thanks !
  21. Good day, I'm working on a script and this script list folder in a html list. Here is the code; <html> <head> <style type="text/css"> ul { list-style-image: url(Icons/box_icon.png); } li li { list-style-image: url('Icons/open_book_icon.jpg'); } li li li { list-style-image: url('Icons/gallery.gif'); } </style> </head> <body> <?PHP function globDir($dir) { $files = glob("$dir/*", GLOB_ONLYDIR); if(!empty($files)) { echo "<ul>\n"; foreach($files as $file) { echo "<li>"; echo "<b>". basename($file)."</b>\n"; globDir($file); echo "</li>\n"; } echo "</ul>\n"; } } globDir('Photos'); ?> </body> </html> example folder | - Folder 1 - Folder 2 | - Folder2.1 | - Folder3 The deal here is that I could go by CSS level of list but my problem is that sometime there is more subfolder yhat this example. Is there a way that I can tell the last level folder to be written in bold ? Thanks !
  22. Good day to you all, is there a way to check if a specific folder contains: files, folder, both or none ? I read my folder with Glob, like my code here : <?PHP function globDir($dir) { $files = glob("$dir/*", GLOB_ONLYDIR); if(!empty($files)) { echo "<ul>\n"; foreach($files as $file) { echo "<li><b>". basename($file)."</b>\n"; globDir($file); echo "</li>\n"; } echo "</ul>\n"; } } globDir('Photos'); ?> The only thing I have really found is how to find if a specific file exists. I'm trying to find out if a specific folder contains : files, folders, both, none. It would return the appropriate word accordingly. Thanks and take care!
  23. What I really tried to obtain is : Folder that has folder in them use one icon Folder that has files it them use another icon Can I do it ?
  24. Good day to you all, I was wondering if there is a way to change the the look of wach level of a list. Ex: Last level, text = link 1st level, has 1 image instead of bullet and text in bold 2nd level as another image as bullet and text in bold 3rd level, if not last level, as another image as bullet and text in bold\ Here is where I'm now : <html> <head> <style type="text/css"> ul { list-style-image: url(Icons/open_book_icon.jpg); } li { list-style-image: url(Icons/box_icon.png); } </style> </head> <body> <?PHP function globDir($dir) { $files = glob("$dir/*", GLOB_ONLYDIR); if(!empty($files)) { echo "<ul>\n"; foreach($files as $file) { echo "<li><b>". basename($file)."</b>\n"; globDir($file); echo "</li>\n"; } echo "</ul>\n"; } } globDir('Photos'); ?> </body> </html> Thanks !
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.