PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
//please correct my logic. I need to make those variables $topicid, $topic, $sentid & $sent as arrays which I need to use them outside those local loops.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
<?php
require_once("includes/connection.php");
$dataArray1 = array();
$dataArray2 = array();
$resultArray = array();
$topics = mysql_query("SELECT * FROM trendingtopics ORDER BY topicid") or die(mysql_error());
if(mysql_num_rows($topics)!=0)
{
$x=0;
while($row_topics = mysql_fetch_array($topics))
{
$dataArray1['topic_id'][$x] = $row_topics['topicid'];
$dataArray1['topic'][$x] = $row_topics['topic'];
$x++;
}
}
else
{
echo "no topic";
}
$sentences = mysql_query("SELECT * FROM sentences ORDER BY sentid") or die(mysql_error());
if(mysql_num_rows($sentences)!=0)
{
$x=1;
while($row_sentences = mysql_fetch_array($sentences))
{
$dataArray2['sent_id'][$x] = $row_sentences['sentid'];
$dataArray2['sent'][$x] = $row_sentences['sent'];
$x++;
}
}
else
{
echo "No sentences";
}
//I need to concatenate each topic with each sentence. My two foreach loops are not concatenating as expected... Need correction here
foreach($dataArray1['topic'] as $eachTopic)
{
foreach($dataArray2['sent'] as $eachSent)
{
$resultArray[] = $eachTopic." ".$eachSent;
print_r($resultArray);
echo "<br \>";
}
}
?>