Jump to content

sasa

Staff Alumni
  • Posts

    2,804
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by sasa

  1. <?php
    $titles_list = array(1,2,3);
    $prices_list = array(11,22,33);
    $services_list = array(111,222,333);
    reset($titles_list);
    reset($prices_list);
    reset($services_list);
    $title = current($titles_list);
    $price = current($prices_list);
    $service_id = current($services_list);
    while ($title and $price and $service_id){
        mysql_query("INSERT INTO product_invoices (name, invoice_id, price, quantity, date_time, service_id) VALUES('$title', '$invoice_id', '$price', '$today_slashes', '$service_id')") or die(mysql_error());
        
        $title = next($titles_list);
        $price = next($prices_list);
        $service_id = next($services_list);
    }
    ?>

  2. try

    <?php
    $hierarchy=array();
    $hierarchy[]=array('id' => 1, 'parent_id'  => 0, 'name' => 'root1');
    $hierarchy[] = array('id' => 2, 'parent_id' => 0, 'name' => 'root2');
    $hierarchy[] = array('id' => 3, 'parent_id' => 1, 'name' => 'root1-1');
    $hierarchy[] = array('id' => 4, 'parent_id' => 1, 'name' => 'root1-2');
    $hierarchy[] = array('id' => 5, 'parent_id' => 3, 'name' => 'root1-1-1');
    $hierarchy[] = array('id' => 6, 'parent_id' => 2, 'name' => 'root2-1');
    function find_pat($a, $n, $key='name' ){
        $out = array();
        foreach ($a as $r){
            if ($r[$key] == $n){
                $out = find_pat($a, $r['parent_id'],'id');
                $out[]=$r;
            }
        }
        return $out;
    }
    $a = find_pat($hierarchy, 'root1-1-1');]
    print_r($a);
    ?> 

  3. SELECT 
    group_concat(if((select count(b.id) from table b where b.id <= a.id and a.grup = b.grup)=1, a.name, '') separator '') name_1,
    group_concat(if((select count(b.id) from table b where b.id <= a.id and a.grup = b.grup)=2, a.name, '') separator '') name_2,
    group_concat(if((select count(b.id) from table b where b.id <= a.id and a.grup = b.grup)=3, a.name, '') separator '') name_3,
    group_concat(if((select count(b.id) from table b where b.id <= a.id and a.grup = b.grup)=4, a.name, '') separator '') name_4,
    group_concat(if((select count(b.id) from table b where b.id <= a.id and a.grup = b.grup)=5, a.name, '') separator '') name_5
    
    FROM table a 
    
    group by a.grup
    
    ORDER BY a.id

  4. $result = mysql_query("select * from staff'");
    $i=0:
    
    echo "<table border='0' cellpadding='10' cellspacing='0'>";
    //echo "<tr>";
    while($row = mysql_fetch_array($result))
    {
    if($i == 0) echo '<tr>';
    $i++;
    echo "<td><img src=../upload/".$row['Pic']." border='0' width='140' height='105' /></td>";
    echo "<td>".$row['Name']."</br><b>".$row['Role']."</b></td>";
    if($i==2){echo '</tr>'; $i=0;}
    }
    if($i>0)echo "<td> </td></tr>";
    echo "</table>";

  5. change your function to

    function somefunction($vaiable) {
    $gers = mysql_query(sprintf("SELECT emp_id, lastname FROM info WHERE active='1' AND oid='$oid' AND pidnumber='4'")) or die(mysql_error());
    $out ='';
    while ($gerow = mysql_fetch_array($gers)) { 
    $out .= "ci.attorney='$lastnamey' OR ";
    
    }
    return $out;
    }[>/code]

  6. try

    if(isset($_GET['lang'])) {
       switch($_GET['lang']) {
          case 'zh-hans':
             	include (TEMPLATEPATH . '/branches-cn.php');  //branches pages contains the translated images
             break;
    
          case 'zh-hant':
            	include (TEMPLATEPATH . '/branches-tcn.php'); 
             break;
    
          default:
             include (TEMPLATEPATH . '/branches.php'); //This is my english page 
             break;
       }
    } else  include (TEMPLATEPATH . '/branches.php');

  7. or

    <?php
    $test ='"STEAM_0:0:18130940"	
    {
    "admin"	"(Console)"
    "unban"	"1274151724"
    "time"	"1273546924"
    "name"	"-=SAS=- Death Master511"
    "reason"	"Gcombat on spawn/Server Crash Attempts 1 week appeal at halania.com"
    }
    "STEAM_0:1:6428933"	
    {
    "time"	1273619777
    "unban"	1273706177
    "admin"	"TornadoChas3r(STEAM_0:0:19768725)"
    "name"	".:T.¥:. TRÅÑŒ (CRYSTAL)"
    "reason"	"RDM/ 1 day Ban \"You had Enough Warnings\" / :"
    }
    ';
    $test = preg_replace('/"(STEAM_[^"]+)"/', '[$1]', $test);
    $test = preg_replace('/\{|}/', '', $test);
    $test = preg_replace('/"([^"]+)"\t+([^ ])/S', '$1=$2', $test);
    
    $test = parse_ini_string($test, 1);
    print_r($test);
    ?> 

  8. try

    <?php
    $string_parts = 4;
    $max = 10000;
    $arr = array();
    $i = 0;
    $start = memory_get_usage();
    $ar =  array_pad(array(), 4, "A");
    for(;$i<$max;$i++){
    //$arr[] = array_pad(array(), 4, "A");
    $arr[] = $ar;
    }
    $end = memory_get_usage();
    printf("%d iterations, %d bytes in array\n", $max, $end-$start);
    
    
    $arr2 = array();
    $i = 0;
    $ar = array("A", "A", "A", "A");
    $start2 = memory_get_usage();
    for(;$i<$max;$i++){
    $arr2[] = $ar;
    //$arr2[] = array('A', 'A', 'A', 'A');
    //$arr2[] = array_fill(0,4,'A');
    }
    $end2 = memory_get_usage();
    printf("%d iterations, %d bytes in array (%.2f%%)\n", $max, $end2-$start2, ($end2-$start2)/($end-$start)*100);
    ?> f/code]

  9. try

    for($i = 0; $i < $num_course; $i++) // num_course is the number of arrays (course0,course1) that are recieved
    		{
                      
                     $test = "course".$i;
         
                     for($x = 0; $x < sizeof($$test); $x++) //ad one more $
                       {
    
                       echo($$test[$x]); //same here
                       }
    
                            }

×
×
  • 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.