Php dizi mysql Mağaza haber!

2 Cevap php

Ben senaryoyu şu var:

$cbid = 0;
	$arrayid = 0;
	while ($FINDNEWSresult = mysql_fetch_array($FINDNEWSquery)) {
		echo "<tr>";
		// Prvi stolpec - označevanje (checkbox)
		echo "<td class=\"middlerow checkbox\"><input id=\"" . $FINDNEWSresult['NEWSid'] . "\" type=\"checkbox\" /></td>";
		echo "<td class=\"middlerow\"><a class=\"ahover\" href=\"?mod=news&command=edit&edit=true&id=" . $FINDNEWSresult['NEWSid'] ."\">" . substr($FINDNEWSresult['NEWStitle'], 0, $MOD_NEWStextlimit)  . "</a></td>";
		echo "<td class=\"middlerow\"><a class=\"ahover\" href=\"?mod=news&command=edit&edit=true&id=" . $FINDNEWSresult['NEWSid'] ."\">" . substr($FINDNEWSresult['NEWStext'], 0, $MOD_NEWStextlimit) . "</a></td>";
		echo "<td class=\"middlerow\">" . $FINDNEWSresult['NEWSuser'] . "</td>";
		echo "<td class=\"middlerow\">" . $FINDNEWSresult['NEWSdate'] . "</td>";
		echo "</tr>";
		$NEWSarray = array ( $arrayid => array ( "Id" => $FINDNEWSresult['NEWSid'],
												 "Title" => $FINDNEWSresult['NEWStitle'],
												 "Text" => $FINDNEWSresult['NEWStext'],
												 "User" => $FINDNEWSresult['NEWSuser'],
												 "Date" => $FINDNEWSresult['NEWSdate']
												)
							);
		// Povecaj $cb zarad checkbox id
		$cbid++;
		$arrayid++;
	}

How to modify script, that array will be filled with each news? Currently, array stores only last news.

Yardımın için teşekkürler!

2 Cevap

Bu gibi:

$cbid = 0;
        $arrayid = 0;
    	$NEWSarray = array(); // Not necessary but good for clarity
        while ($FINDNEWSresult = mysql_fetch_array($FINDNEWSquery)) {
                echo "<tr>";
                // Prvi stolpec - oznacevanje (checkbox)
                echo "<td class=\"middlerow checkbox\"><input id=\"" . $FINDNEWSresult['NEWSid'] . "\" type=\"checkbox\" /></td>";
                echo "<td class=\"middlerow\"><a class=\"ahover\" href=\"?mod=news&command=edit&edit=true&id=" . $FINDNEWSresult['NEWSid'] ."\">" . substr($FINDNEWSresult['NEWStitle'], 0, $MOD_NEWStextlimit)  . "</a></td>";
                echo "<td class=\"middlerow\"><a class=\"ahover\" href=\"?mod=news&command=edit&edit=true&id=" . $FINDNEWSresult['NEWSid'] ."\">" . substr($FINDNEWSresult['NEWStext'], 0, $MOD_NEWStextlimit) . "</a></td>";
                echo "<td class=\"middlerow\">" . $FINDNEWSresult['NEWSuser'] . "</td>";
                echo "<td class=\"middlerow\">" . $FINDNEWSresult['NEWSdate'] . "</td>";
                echo "</tr>";
                $NEWSarray[] = array ( $arrayid => array ( "Id" => $FINDNEWSresult['NEWSid'],
                                                                                                 "Title" => $FINDNEWSresult['NEWStitle'],
                                                                                                 "Text" => $FINDNEWSresult['NEWStext'],
                                                                                                 "User" => $FINDNEWSresult['NEWSuser'],
                                                                                                 "Date" => $FINDNEWSresult['NEWSdate']
                                                                                                )
                                                        );
                // Povecaj $cb zarad checkbox id
                $cbid++;
                $arrayid++;
        }

Alternatif için [] siz de PHPs array_push kullanabilirsiniz.

Tekrar tekrar tüm yaratmak için değil, diziye eklemek gerekir.

$NEWSarray[] = <new_element> ;

veya

array_push($NEWSarray, <new_element>);