Hello,
I am looking for a php code to generate a unique record from sql database. I have no idea how to do this. If you know then please post here, it would really help me a lot. Thank you for your help.
Hello,
I am looking for a php code to generate a unique record from sql database. I have no idea how to do this. If you know then please post here, it would really help me a lot. Thank you for your help.
Hello,
I think this can solve your problem, just give it a try
Code:$qry = "select DISTINCT name FROM table WHERE name LIKE string"; $rsl = my_qry($qry) or die (mysql_error()); //$row = mysql_fetch_array($rsl); while ($row = mysql_fetch_array($rsl)) { echo $row["name"]; }
Hello,
You can try the following code , though I am not sure that this is the perfect code that your are looking for
Code:<?php class appmd extends md { function isunq($field, $value, $id) { $flds[$this->name.'.'.$field] = $value; if (empty($id)) // add $flds[$this->name.'.id'] = "<> NULL"; else // edit $flds[$this->name.'.id'] = "<> $id"; $this->recursive = -1; if ($this->hasAny($flds)) { $this->invalidate('unique_'.$field); return false; } else return true; } ?>
Hello,
Alternatively you can use this code
Code:<?php if ($this->User->unq('username', $this->data['User']['username'], $user_id)) { if ($this->User->save($this->data)) { $this->flash('User has been saved.','/users/index'); } } ?>
Hello,
Take a look at the following code
Code:if (empty($id)){ // add $cnd = $this->name.".".$flds." = '".$value."'"; }else{ // edit $flds[$this->name.'.id'] = "<> $id"; $conditions = '('.$this->name.".".$flds." = '".$value."') AND (".$this->name.".id <> $id)"; }
Hello,
Try the following code
Code:if (empty($id)) // add $flds[$this->name.'.id'] = "!= NULL"; else // edit $flds[$this->name.'.id'] = "!= $id";
Hello,
Check the modified code
Code:$qry = "select DISTINCT name FROM `atable` WHERE name LIKE '%john%'"; $rst = mysqlqry($qry) or die (mysql_error()); $row = mysqlarry($rst); while ($row = mysqlarry($rst)) { echo $row["name"]; }
Bookmarks