sasa
Staff Alumni-
Posts
2,804 -
Joined
-
Last visited
-
Days Won
1
Everything posted by sasa
-
[SOLVED] Displaying table results in multi column table
sasa replied to rvdb86's topic in PHP Coding Help
some like this <?php $count = 0; echo '<table border="3">'; for ($i=0;$i<10;$i++){ //start loop if ($count == 0) echo '<tr>'; $count++; echo '<td>',$i,'</td>';// echo some data in td tag if ($count == 3){ echo '</tr>'; $count=0; } } //end loop if ($count>0){ for (;$count<3;$count++) echo '<td> </td>'; echo '</tr>'; } echo '</table>'; ?> -
for your 1st code try <?php $_POST['Bin'][23]='Throw Away';//posted by form $ids = array_keys($_POST['Bin']); echo $id = strtolower(mysql_real_escape_string(stripslashes($ids[0]))); ?>
-
change line $array_of_subscribers.="'".$array_user_id."'".$array_comma; to $array_of_subscribers[]=$array_user_id; and if(in_array($needle, $test_array)){ to if(in_array($needle, $array_of_subscribers)){
-
try <?php $i = 1; $data = fgetcsv($handle, 1000, ","); while ($data !== FALSE) { // check if last loop if (($data1 = fgetcsv($handle, 1000, ",")) == false){ echo 'last loop'; } print_r($data); $i++; $data = $data1; } ?>
-
Update query to switch the values of 2 table rows PHP Mysql
sasa replied to sngumo's topic in PHP Coding Help
http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_if -
Update query to switch the values of 2 table rows PHP Mysql
sasa replied to sngumo's topic in PHP Coding Help
UPDATE menu SET `menu_order` = IF( menu_order =$old_position, $new_position, $old_positon ) WHERE menu_order IN ( $old_position, $new_position ) -
<?php foreach($_POST['title'] as $key => $value){ //code here $caption = $_POST['caption'][$key]; echo "Title is $value and caption is $caption<br />\n"; } ?>
-
try <?php $array_of_pos = array(1,2,3,4,5); for ($i=0;$i<10000;$i++){ foreach ($array_of_pos as $pos) //create new value foreach positions $tmp[$pos] = ($pos + 7) * rand(); asort($tmp);//sort new array $tmp = array_flip($tmp); $first = array_shift($tmp);//get 1st element $out[]=$first; // put element for analise } $distribution = array_count_values($out); ksort($distribution); print_r($distribution); ?>[7php]
-
form field named city doesn't exist in form
-
if you have 20 items per page and 3 columns it is 6 full rows + 2 items
-
Removing duplicate values in multidimensional array HELP!
sasa replied to brendz's topic in PHP Coding Help
try <?php function remove_duplicate($items){ $count = count($items); $names = array(); $items1 = array(); for ($i = 0; $i < $count; $i ++) { if (!in_array($items[$i]->name, $names)){ $names[] = $items[$i]->name; $items1[] = $items[$i]; } } return $items1; } $items = remove_duplicate($items); ?> -
run code when a loop gets the last item of an array
sasa replied to Darkmatter5's topic in PHP Coding Help
<?php echo 'Code 1:<br />'; $list = array(1,2,3,4); echo implode(', ', $list); echo "<hr />\n"; echo 'Code 2:<br />'; $list = array(1,2,3,4); $pre = ''; foreach ($list as $item){ echo $pre, $item; $pre = ', '; } echo "<hr />\n"; echo 'Code 3:<br />'; $list = array(1,2,3,4); $last = array_pop($list); foreach ($list as $item){ echo $item, ', '; } echo $last; echo "<hr />\n"; echo 'Code 4:<br />'; $list = array(1,2,3,4); $i = 0; while (isset($list[$i +1])){ echo $list[$i++], ', '; } echo $list[$i]; echo "<hr />\n"; //etc. ?> -
try <?php if (isset($_POST['Submit'])){ foreach ($_POST['data'] as $ID => $uValue) { mysql_query("UPDATE titles SET uValue='$uValue' WHERE ID='$ID'"); } } ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <table> <?php $UserID =3; //UserID as user id, uTitle as user title, uValue as description/value of title connect(); $query = "SELECT * FROM titles WHERE UserID = $UserID"; $result = mysql_query($query); if (mysql_num_rows($result)){ //$row = mysql_fetch_assoc($result); echo "<br /><b>Edit your data:</b> <br /><br />"; while($row = mysql_fetch_assoc($result)) { extract ($row); echo " <tr> <td><b>$uTitle</b></td> <td><input type='text' name='data[$ID]' value='$uValue'></td> </tr>"; } } else echo 'No data to edit'; ?> <tr><td><input type="submit" value="Submit"></td> </tr> </table> </form>
-
[SOLVED] sort() function not sorting numbers correctly
sasa replied to Someone789's topic in PHP Coding Help
rsort($numbers); print_r($numbers); -
value=" <?php echo $a_row[0]; ?>"
-
$max = 10; $num = $page * $max - $max; $totalpage = ceil($lines / $max) + 1; // $page = 1; $show = 9; $start = (int) max(1, min($page - floor(($show - 1)/2), $totalpage - $show + 1)); $end = min($totalpage, $start + $show - 1); if ($page > 1) { echo "<a href=\"?action=index&p=".($page-1)."\"><span id=\"paging\">Previous</span></a> \n"; } else if($page <= 1) { echo "<span id=\"paging\">Previous</span> \n"; } for($i = $start; $i <= $end; $i++) { if($i == $page) { echo "<span id=\"paging\">$i</span> \n"; } else { echo "<a href=\"?action=index&p=".$i."\"><span id=\"paging\">$i</span></a> \n"; } } if ($page < $totalpage - 1) { echo "<a href=\"?action=index&p=".($page + 1)."\"><span id=\"paging\">Next</span></a>\n"; } else if($page >= $totalpage - 1) { echo "<span id=\"paging\">Next</span>\n"; }
-
run code when a loop gets the last item of an array
sasa replied to Darkmatter5's topic in PHP Coding Help
or <?php $list = array(1,2,3,4,5); $last_element = array_pop($list); foreach ($list as $element) { echo "$element isn't last.<br />\n"; } echo "$last_element is last.<br />\n"; ?> -
you didn't close bracket in IN part of query
-
move lines $entriesperline=4; $counter=1; print "<table>"; before foreach loop
-
echo '<div class="cat_name">[<a href="',$row_rssql['category_name'],'">',$row_rssql['category_name'],"</a>]</div>\n ";
-
ups i made mistake in line 18 in posted code change $_SESSION['items']['$item_to_add']++; to $_SESSION['items'][$item_to_add]++;
-
<style> .cat_name { display: inline; margin: 0 2 0 0; border: 2 solid red; padding: 2 6 3 6; color: white; background-color: blue; } </style>
-
try <?php session_start(); if(isset($_GET['clearlist'])){ session_destroy(); }else{ $item_to_add = $_GET['item']; if ( ! isset ( $_SESSION['items'] ) ) { echo "no items set... adding item"; $_SESSION['items'][$item_to_add] = 1; } else { if ( ! isset($_SESSION['items'][$item_to_add] ) ) { echo "there is items, but this item doesn't exist"; $_SESSION['items'][$item_to_add] = 1; } else { echo "there is items, and this item exist, so adding to qty"; $_SESSION['items']['$item_to_add']++; } } if ( isset ( $_SESSION['items'] ) ) { foreach($_SESSION['items'] AS $key => $qty){ echo $key . "x" . $qty ."<br />"; } } else { echo "No Items exist!"; } } ?>
-
while($row_rssql = mysql_fetch_assoc($rssql)) echo '<div class="cat_name">',$row_rssql['category_name'],"</div>\n"; and add CSS to format it