sasa
Staff Alumni-
Posts
2,804 -
Joined
-
Last visited
-
Days Won
1
Everything posted by sasa
-
try <?php if (mysql_num_rows($result) == 0) { echo "No news yet"; } ?>
-
change line echo "<td>$food</td>"; to if (in_array($id_food, $db_array)) echo "<td>$food</td>";
-
remove man_date condition from WHERE part in $sql2
-
try <?php function deter($a, $i = -1){ if ($i < 0) $i = count($a) -1; if ($i==0) return $a[0][0]; $j = $i; $sig = 1; while ($a[$j][$i] == 0 and $j-- > -1); if ($i != $j and $a[$j][$i] != 0) { $tmp = $a[$i]; $a[$i] = $a[$j]; $a[$j] = $tmp; $sig *= -1; } else if($a[$j][$i] == 0) return 0; $b = $a[$i][$i]; for ($row = $i -1; $row >= 0; $row--){ $c = -$a[$row][$i] / $b; for ($k = 0; $k < $i; $k++){ $a[$row][$k] += $a[$i][$k] * $c; } } return $out = $b * deter($a, $i - 1) * $sig; } $matr = array( array(0,2,0), array(3,4,2), array(6,0,0) ); echo deter($matr); ?>
-
try echo "<a href=\"lists.php?action=$action&page=$npage&sid=$sid&view=$view\">Next</a>";
-
Deleting from database by checking multiple checkboxes
sasa replied to sparky753's topic in PHP Coding Help
if name of your checkboxs is "chk[]" and value of ID is numeric and form metod is POST on submit page do $ids = implode(', ', $_POST['chk']); $sql = "DELETE FROM table_name WHERE ID IN ($ids)"; -
insert ignore into two tables (mysql 5.0) php.
sasa replied to sayedsohail's topic in PHP Coding Help
or mysql_query("INSERT INTO `fmodels` (`member_id`, `make_id`, `model`, `model_date`, `description`) VALUES ('$memid', '$fm', '$fmod','$today', '$fdes'); INSERT INTO `table2` (`member_id`, `make_id`, `model`, `model_date`, `description`) VALUES ('$memid', '$fm', '$fmod','$today', '$fdes')"); -
[SOLVED] whats the best way to display a random record from a mysql table?
sasa replied to daveh33's topic in PHP Coding Help
change line $result = mysql_fetch_row(mysql_query("SELECT * from promotions where used='n' ORDER BY RAND(id)") or die(mysql_error())); to $result = mysql_query("SELECT * from promotions where used='n' ORDER BY RAND()") or die(mysql_error()); -
OK i made typo in fetch cirrect cide is //query database $result = mysql_query($sql); //echo table header $data_per_row = 3; echo '<table border="3">'; while($row = mysql_fetch_row($result)) { //start new row echo '<tr>'; //echo 1st data echo "<td>",$row[0],'</td>'; for($i = 1; $i < $data_per_row; $i++) { if($row = mysql_fetch_row($result)) echo "<td>",$row[0],'</td>'; else echo "<td>",' ','</td>'; } echo '</tr>'; } echo '</table>'; ?>
-
another solution //query database $result = mysql_query($sql); //echo table header $data_per_row = 3; echo '<table>'; while($row = mysql_featch_row($result)) { //start new row echo '<tr>'; //echo 1st data echo "<td>",$row['field_name'],'</td>'; for($i = 1; $i < $data_per_row; $i++) { if($row = mysql_featch_row($result)) echo "<td>",$row['field_name'],'</td>'; else echo "<td>",' ','</td>'; } echo '</tr>'; } echo '</table>';
-
try UPDATE `users` SET name='B' WHERE name='A' ORDER BY RAND() LIMIT 5
-
in function change echo to return
-
SELECT id FROM users ORDER BY ABS(f1 + f2 + f3 - 60) LIMIT 1
-
try <?php $input = array( array('parent_id' => 1, 'child_id' => 2), array('parent_id' => 2, 'child_id' => 3), array('parent_id' => 3, 'child_id' => 4), array('parent_id' => 3, 'child_id' => 5), array('parent_id' => 5, 'child_id' => 6), array('parent_id' => 5, 'child_id' => 7) ); function my_tree($input, $start = false) { //find start node $p = array(); $c = array(); foreach ($input as $key => $v) { $p[$key] = $v['parent_id']; $c[$key] = $v['child_id']; } if ($start === false){ $start = array_diff($p,$c); $start = array_unique($start); } foreach ($start as $parent) { $keys = array_keys($p, $parent); $tmp = array(); foreach ($keys as $k) { $tmp1 = my_tree($input, array($c[$k])); echo ''; $tmp = array_merge($tmp, $tmp1); } if (count($tmp)==0) { $out[] = array('ID' => $parent); } else $out[]=array('ID' => $parent, 'CHILDs' => $tmp); } return $out; } $a = my_tree($input); print_r($a); ?>
-
ups extra ')' in the end $insert = "INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('" . $userId . "', '" . $userPass . "');";
-
$insert = "INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('" . $userId . "', '" . $userPass . "'));";
-
are you use method="POST" in your form? name of checkbox is karakey and you check cotkey, is it OK?
-
or see http://www.phpfreaks.com/forums/index.php/topic,155530.0.html
-
insert before line $data = $name . ',' . $email . ',' . $phone . ',' . $organization . ',' . $designation . ',' . $enquiry . ',' . $date . $cr; line $enquiry = nl2br($enquiry);
-
change line echo 'Item Code: ', $ProductId, '<br/>Item Name: ', $ProductName, '<br/><br/>Price: £', $Price, ' | Order: <input name=checker type=checkbox /> Quantity: <input name=quan type=text maxlength=5 size=3 /><br/><br/>'; to echo 'Item Code: ', $ProductId, '<br/>Item Name: ', $ProductName, '<br/><br/>Price: £', $Price, ' | Order: <input name="checker[', $ProductId, ']" type="checkbox" /> Quantity: <input name="quan[', $ProductId, ']" type="text" maxlength="5" size="3" /><br/><br/>';
-
change function preg_replace() to str_replace()
-
try <? $filename = "filename.txt"; $filepointer = fopen($filename, "r"); $myarray = file ($filename); for ($mycount = 0; $mycount < count ($myarray);$mycount++) { $aline = $myarray[$mycount]; $cd = str_replace(',',"<br />\n", $aline); //$cd = getvalue($myarray[0], $mycount); print "$cd" . "<br> \n"; } function getvalue($file, $mycount) { $intoarray = explode (",", $file); return $intoarray[$mycount]; } fclose($filepointer); ?>
-
[SOLVED] building an array with mysql results, then parsing them
sasa replied to scarhand's topic in PHP Coding Help
try to change line for ($i = 0; $i < sizeof($words); $i++) to for ($i = 0; $i < sizeof($badwords); $i++) -
[SOLVED] Recursive function to restructure a 2d array
sasa replied to kpesanka's topic in PHP Coding Help
try <?php function my_convert($a, $start = 0){ foreach ($a as $id) $tmp[$id['ID']] = $id[parentID]; return my_con($tmp, $start); } function my_con ($a, $start = 0){ $out = array(); $keys = array_keys($a, $start); foreach ($keys as $id) { $child = my_con($a, $id); if (count($child)) $out[] = array('ID' => $id, 'children' => $child); else $out[] = array('ID' => $id); } return $out; } $a = array( array('ID'=>1, 'parentID'=>0), array('ID'=>2, 'parentID'=>1), array('ID'=>3, 'parentID'=>1), array('ID'=>4, 'parentID'=>2), array('ID'=>5, 'parentID'=>2), array('ID'=>6, 'parentID'=>4) ); $b = my_convert($a); print_r($b); ?>