Need help with array

Discussion in 'PHP' started by host-portal, Dec 22, 2007.

  1. #1
    i have an array.
    i need to print it.
    can anyone help me ?
    my code is.
    
    $req['mysql'] = 'Mysql Version';
    $req['php'] = 'PHP Version >= 4.1.0 :';
    if (!version_compare("4.1.0", phpversion(), "<=")) {
    $errors[] = '<img src="images/error.gif" />  Your PHP version'.phpversion().' is incompatible with this script.';
    }
    else {
    $text[] = '<img src="images/tick.gif" />  Your PHP version'.phpversion().' is compatible with this script.';
    }
    
    if (find_SQL_Version() <="4.1.0") {
    $errors[] = '<img src="images/error.gif" /> MySQL Support: Your MySQL version'.find_SQL_Version().' is incompatible with this script.';
    }
    else {
    $text[] = '<img src="images/tick.gif" /> MySQL Support: Your MySQL version'.find_SQL_Version().' is compatible with this script.';
    
    
    
    foreach($req as $reqs) {
    
    echo '<div class="list">';
    echo '<ul>';
    	while (list($key,$value) = each($errors)) {
    	if (empty($value)) {
    	} 
    	else {
    	echo "<li>".$reqs."".$value."</li>";
    	}
    	}
    	while (list($key,$value) = each($text)) {
    	if (empty($value)) {
    	} 
    	else {
    	echo "<li>".$reqs."".$value."</li>";
    	}
    	}
    echo "</ul>";
    echo '</div>';
    }
    }
    PHP:
    it isnt working,
    it is just printing mysql version again and again on the output.
    can anyone help me?
     
    host-portal, Dec 22, 2007 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    Should be:

    
    
    $req[0] = array('php','PHP Version >= 4.1.0 :');
    $req[1] = array('mysql','Mysql Version');
    
    if (!version_compare("4.1.0", phpversion(), "<=")) {
    $errors[0] = '<img src="images/error.gif" />  Your PHP version'.phpversion().' is incompatible with this script.';
    }
    else {
    $text[0] = '<img src="images/tick.gif" />  Your PHP version'.phpversion().' is compatible with this script.';
    }
    
    if (find_SQL_Version() <="4.1.0") {
    $errors[1] = '<img src="images/error.gif" /> MySQL Support: Your MySQL version'.find_SQL_Version().' is incompatible with this script.';
    }
    else {
    $text[1] = '<img src="images/tick.gif" /> MySQL Support: Your MySQL version'.find_SQL_Version().' is compatible with this script.';
    
    foreach($req as $sub => $item){
        echo '<div class="list">';
        echo '<ul>';
        echo "<li>".$sub[0]."".$errors[$sub].$text[$sub]."</li>";
        echo '</ul>';
        echo '</div>';
    }
    
    
    PHP:
    Peace,
     
    Barti1987, Dec 22, 2007 IP
  3. host-portal

    host-portal Banned

    Messages:
    227
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    lol no , u are doing it wrong , it cant be :
    else {
    $text[1] = '<img src="images/tick.gif" /> MySQL Support: Your MySQL version'.find_SQL_Version().' is compatible with this script.';

    foreach($req as $sub => $item){
    echo '<div class="list">';
    echo '<ul>';
    echo "<li>".$sub[0]."".$errors[$sub].$text[$sub]."</li>";
    echo '</ul>';
    echo '</div>';
    }

    or it will only execute the foreach thing if sql version will be lower than "4.1.0"
     
    host-portal, Dec 23, 2007 IP
  4. Vio82

    Vio82 Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Just printing array?
    Use print_r();

    or echo "<pre>".print_r($your_array)."</pre>";
     
    Vio82, Dec 23, 2007 IP
  5. host-portal

    host-portal Banned

    Messages:
    227
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i need to print 2 arrays if u can read.
     
    host-portal, Dec 25, 2007 IP