oprette totalrecords i foreach
Hej alle,Mit problem er at jeg skal hente data i en database som så laver en foreach tabel med data i.
i den tabel skal der så hentes data fra en anden database, men kun en record som afgøres af den enkelte række.
Række 1
Kol 1:
TITEL
ID[db1] (her er ID 1)
Kol 2:
Antal reccords hvor MESSAGE = 'MYMCD V ID[db1]' (her er ID 1)
Række 2
Kol 1:
TITEL
ID[db1] (her er ID 2)
Kol 2:
Antal reccords hvor MESSAGE = 'MYMCD V ID[db1]' (her er ID 2)
Min kode:
<?php require_once('../Connections/hosting.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_votesresult = $_GET['vote'];
mysql_select_db($database_hosting, $hosting);
$query_votesresult = sprintf("SELECT * FROM vote_list WHERE vote_table = %s ORDER BY title ASC", GetSQLValueString($colname_votesresult, "int"));
$votesresult = mysql_query($query_votesresult, $hosting) or die(mysql_error());
$row_votesresult = mysql_fetch_assoc($votesresult);
$totalRows_votesresult = mysql_num_rows($votesresult);
$colname_votesinfo = $_GET['vote'];
mysql_select_db($database_hosting, $hosting);
$query_votesinfo = sprintf("SELECT * FROM vote_table WHERE id = %s", GetSQLValueString($colname_votesinfo, "int"));
$votesinfo = mysql_query($query_votesinfo, $hosting) or die(mysql_error());
$row_votesinfo = mysql_fetch_assoc($votesinfo);
$totalRows_votesinfo = mysql_num_rows($votesinfo);
?><p><strong>Afstemnings resultater</strong></p>
<p><em>for <?php echo $row_votesinfo['title']; ?></em></p>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td>Mulighed</td>
<td>Antal svar</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_votesresult['title']; ?><br>
mymcd v <?php echo $row_votesresult['id']; ?></td>
<td>
<?php
$colname_votessms = 'Mymcd v 1';
mysql_select_db($database_hosting, $hosting);
$query_votessms = sprintf("SELECT * FROM smsnet WHERE message = %s", GetSQLValueString($colname_votessms, "text"));
$votessms = mysql_query($query_votessms, $hosting) or die(mysql_error());
$row_votessms = mysql_fetch_assoc($votessms);
$totalRows_votessms = mysql_num_rows($votessms);
?>
<?php echo $totalRows_votessms ?> svar</td>
</tr>
<?php } while ($row_votesresult = mysql_fetch_assoc($votesresult)); ?>
</table>
<?php
mysql_free_result($votesresult);
mysql_free_result($votesinfo);
?>