Showing Array data - php

I have a foreach below that when print_r or var_dumped it shows the correct data but once I put the $finalMenuDetails into the location I need it shows Array and not the list.
Var_dump
array(3) {
[0]=>
string(6) "Item 1"
[1]=>
string(6) "item 2"
[2]=>
string(6) "item 3"
}
array(3) {
[0]=>
string(2) "23"
[1]=>
string(2) "90"
[2]=>
string(2) "23"
}
PHP
foreach($menuDetailsItem as $key => $value)
{
$finalMenuDetails[] = $value. " ".$amount[$key] . '<br/>';
}
Process:
$menuName = $_POST['menu'];
$menuDetailsItem = $_POST['item'];
$menuDetailsItemAmount = $_POST['amount'];
$menuResult = '';
foreach ($menuDetailsItem as $key => $value) {
$menuResult .= $value." ".$menuDetailsItemAmount[$key]."<br/>";
}
if(empty($errorMessage))
{
$to = "";
$subject = "Booking";
$headers = "From: " . strip_tags($_POST['Email']) . "\r\n" . "Reply-To: ". strip_tags($_POST['Email']) . "\r\n" . "Content-Type: text/html; charset=ISO-8859-1\r\n" . //header("Location: http://redherringcatering.co.nz/Thankyou.html");
$message = "\n" . "<strong>NAME:</strong> ". $varName . "<br />" . "<br />" . "<strong>CONTACT:</strong> " . $varContact . "<br />" . "<br />" . "<strong>EMAIL:</strong> ". $varEmail . "<br />" . "<br />" ."<strong>COMPANY:</strong> ". $varCompany . "<br />" . "<br />" . "<strong>No. ATTENDING:</strong> ".$varAttending . "<br />" . "<br />" ."<strong>FUNCTION DATE:</strong> ". $varFunction . "<br />" . "<br />" ."<strong>FUNCTION DAY:</strong> ". $varFunctionDay . "<br />" . "<br />" ."<strong>DATE ORDERED:</strong> ". $varOrdered . "<br />" . "<br />" ."<strong>TIME REQUIRED:</strong> ". $varTime . "<br />" . "<br />" . "<strong>ONSITE:</strong> ". $varOnsite . ", ". $varOnsite2 . "<br />" . "<br />" ."<strong>INVOICE TO:</strong> ". $varInvoice . "<br />" . "<br />" ."<strong>ADDRESS:</strong>\n". $varAddress . "<br />" . "<br />" ."<strong>SPECIAL NEEDS:</strong> ". $varSpecial . "<br />" . "<br />" . "<strong>ORDER DETAILS:</strong><br/><br/>". $menuName . "<br/>"."<br/>"."<strong>Items:</strong><br/><br/>".print_r($menuResult) . "\n";
mail($to,$subject,$message,$headers);
exit;
}

Try something like this:
$item = array("item 1","item 2","item 3") ;
$amount = array("23","90","23") ;
$result_array = '';
foreach ($item as $key => $value) {
$result_array .= $value." ".$amount[$key]."<br/>";
}
print_r($result_array);
OUTPUT
item 1 23
item 2 90
item 3 23

Related

HTML & PHP Information Table

So i'm hosting servers and trying to make a table displaying the information server name players etc i have a script that displays this but i suck at css, What i'm trying to get is a little like in this website http://echelon.kthx.at/pubbans.php
<?php
include ("BC2Conn.php");
// opens a connection to gameserver
$BC2Conn = new BC2Conn("31.185.143.136", 48888);
if (!$BC2Conn->isConnected()) {
echo "Connection could not be established. " .
"To debug, set '-d' as 3rd parameter to new connection.<br />" .
"<br />" .
"Example: \$BC2Conn = new BC2Conn(\"127.0.0.1\", 48888, \"-d\");";
return 0; // stop executing this script
}
// secure login
// $BC2Conn->loginSecure("password");
// unsecure login (not salted)
// some random serverinformation
echo "Servername: " . $BC2Conn->getServerName() . "<br />";
echo "Players: " . $BC2Conn->getCurrentPlayers() . "/" . $BC2Conn->getMaxPlayers() . "<br />";
echo "Playmode: " . $BC2Conn->getCurrentPlaymodeName() . "<br />";
echo "Current Map: " . $BC2Conn->getCurrentMapName() . "<br /><br /><br /><u>Players:</u><br /><br />";
// playerlist
$playerNames = $BC2Conn->getPlayerlistNames();
foreach ($playerNames as $key => $content) {
if ($BC2Conn->getPlayerClantag($content) != "") {
echo "[" . $BC2Conn->getPlayerClantag($content) . "]";
}
echo " " . $BC2Conn->getPlayername($content) . " - Kills: ";
echo $BC2Conn->getPlayerKills($content) . " | Deaths: ";
echo $BC2Conn->getPlayerDeaths($content) . " | Score: ";
echo $BC2Conn->getPlayerScore($content) . "<br />";
}
// logout
$BC2Conn->logout();
?>

If statements reading entries from database won't show

the below code contains if statements depending on usertype and status. It won't display anything. In the code above i had usertype==1 and status==1 and it is working as it should but this below code won't work. Any suggestions? Please ignore the code i have as i am a beginner and the code is messy.
} else if ($usertype == 2) {
$server1 = "localhost";
$user1 = "r";
$pass1 = "";
$db1 = "";
$db4 = "";
$user5 = $_SESSION['username'];
$mysqli = new Mysqli($server1, $user1, $pass1, $db1) or mysqli_error($mysqli);
$mysqli6 = new Mysqli($server1, $user1, $pass1, $db4) or mysqli_error($mysqli);
$name2= $mysqli6->query("SELECT name FROM head WHERE username= '$user5'")->fetch_object()->name2;
$status2 = $mysqli->query("SELECT status FROM Overrides WHERE head = '$name2'")->fetch_object()->status2;
$headforms = $mysqli->query("SELECT * FROM Overrides WHERE head = '$name2' ");
$num_rows2 = mysqli_num_rows($headforms);
if ($status2 == 2) {
echo "Overrides today: " . $num_rows2;
while($row2 = mysqli_fetch_array($headforms)) {
echo "<br /><br />First Name: " . $row2['name'] . "<br />";
echo "<br />Middle Name: " . $row2['mname'] . "<br />";
echo "<br />Family Name: " . $row2['fname'] . "<br />";
echo "<br />Student ID: " . $row2['sid'] . "<br />";
echo "<br />Scolarship: " . $row2['sc'] . "<br />";
echo "<br />Phone No: " . $row2['phone'] . "<br />";
echo "<br />Email: " . $row2['email'] . "<br />";
echo "<br />Class: " . $row2['class'] . "<br />";
echo "<br />Section: " . $row2['section'] . "<br />";
echo "<br />Semester: " . $row2['semester'] . "<br />";
}
}
?>
Concerning the database entries and data, i have checked them and i'm 100% sure it should display correct info.
I did a test : i tried doing print_r($status2); and print_r($name2); but page is empty, could the problem be with the userype == 2 since it's displaying nothing.
errors:
Notice: Undefined property: stdClass::$name2 in /home/aukwizcq/public_html/override.php on line 310
Notice: Trying to get property of non-object in /home/aukwizcq/public_html/override.php on line 311

How to configure FFMPEG with Xampp in Ubuntu

Hi i am i trying to merge videos using ffmpeg with Php.Now i installed Xampp in ubuntu.and FFMEPG also i installed in Ubuntu.I searched ffmpeg.dll file but its not dound in the directory.but i add the extension in the php.ini file like below my code
;extension=php_bz2.dll
;extension=php_ffmpeg.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_exif.dll
;extension=php_fileinfo.dll
This is my test code for ffmpeg.
<?php
extension_loaded('ffmpeg') or die('Error in loading ffmpeg');
$vid = realpath('1.mp4');
$ffmpegInstance = new ffmpeg_movie($vid);
echo "getDuration: " . $ffmpegInstance->getDuration() . "<br />".
"getFrameCount: " . $ffmpegInstance->getFrameCount() . "<br />".
"getFrameRate: " . $ffmpegInstance->getFrameRate() . "<br />".
"getFilename: " . $ffmpegInstance->getFilename() . "<br />".
"getComment: " . $ffmpegInstance->getComment() . "<br />".
"getTitle: " . $ffmpegInstance->getTitle() . "<br />".
"getAuthor: " . $ffmpegInstance->getAuthor() . "<br />".
"getCopyright: " . $ffmpegInstance->getCopyright() . "<br />".
"getArtist: " . $ffmpegInstance->getArtist() . "<br />".
"getGenre: " . $ffmpegInstance->getGenre() . "<br />".
"getTrackNumber: " . $ffmpegInstance->getTrackNumber() . "<br />".
"getYear: " . $ffmpegInstance->getYear() . "<br />".
"getFrameHeight: " . $ffmpegInstance->getFrameHeight() . "<br />".
"getFrameWidth: " . $ffmpegInstance->getFrameWidth() . "<br />".
"getPixelFormat: " . $ffmpegInstance->getPixelFormat() . "<br />".
"getBitRate: " . $ffmpegInstance->getBitRate() . "<br />".
"getVideoBitRate: " . $ffmpegInstance->getVideoBitRate() . "<br />".
"getAudioBitRate: " . $ffmpegInstance->getAudioBitRate() . "<br />".
"getAudioSampleRate: " . $ffmpegInstance->getAudioSampleRate() . "<br />".
"getVideoCodec: " . $ffmpegInstance->getVideoCodec() . "<br />".
"getAudioCodec: " . $ffmpegInstance->getAudioCodec() . "<br />".
"getAudioChannels: " . $ffmpegInstance->getAudioChannels() . "<br />".
"hasAudio: " . $ffmpegInstance->hasAudio();?>
When i run this in xammp the output coming like this
Error in loading ffmpeg
kindly give some solution for me
thanks in advance.

GeoIP not showing all info

so i have this error , i downloaded the lastest
geoipcity.inc | geoipregionvars.inc | GeoLiteCity.dat
so here is my code :
<?php
/**
* Querying against GeoIP/Lite City
* This will fetch country along with city information
*/
include("geoipcity.inc");
include("geoipregionvars.php");
$giCity = geoip_open("GeoLiteCity.dat",GEOIP_STANDARD);
$ip = "99.99.99.99";
$record = geoip_record_by_addr($giCity, $ip);
echo "Getting Country and City detail by IP Address <br /><br />";
echo "IP: " . $ip . "<br /><br />";
echo "Country Code: " . $record->country_code . "<br />" .
"Country Code3: " . $record->country_code . "<br />" .
"Country Name: " . $record->country_name . "<br />" .
"Region Code: " . $record->region . "<br />" .
"City: " . $record->city . "<br />" .
"Postal Code: " . $record->postal_code . "<br />" .
"Latitude: " . $record->latitude . "<br />" .
"Longitude: " . $record->longitude . "<br />" .
"Metro Code: " . $record->metro_code . "<br />" .
"Area Code: " . $record->area_code . "<br />" ;
geoip_close($giCity);
?>
and here is my problem that
not all resulst are shown :
Country Code: SA
Country Code3: SA
Country Name: Saudi Arabia
Region Code:
City:
Postal Code:
Latitude: 25
Longitude: 45
Metro Code:
Area Code:

fwrite function writes nothing to the file

I am trying to write data into a txt file, but It won't work. there is no error. it just won't work.
here is the code
if (isset($_REQUEST['submit']))
{
$hour = $_REQUEST['hour'];
$family = $_REQUEST['family'];
$how = $_REQUEST['how'];
$will = $_REQUEST['will'];
$fun = $_REQUEST['fun'];
$kind = $_REQUEST['kind'];
$device = $_REQUEST['device'];
$study = $_REQUEST['study'];
$agree = $_REQUEST['agree'];
$text = "hour :" . $hour . "<br />" . "family" . $family . "<br />" . "تطابفق با درس" . $how . "<br />" . "سرگرمی های غیر مجازی : " . $will . "<br />" . "نوع سرگرمی :" . $fun . "<br />" . "kind : " . $kind . "<br />" . "device " . $device . "<br />" . "اثیر بر درس" . $study . "<br />" . "کنترل " . $agree . "<br />" ;
fopen('/1.txt', "r");
fwrite('/1.txt',"hour :" . $hour . "<br />" . "family" . $family . "<br />" . "تطابفق با درس" . $how . "<br />" . "سرگرمی های غیر مجازی : " . $will . "<br />" . "نوع سرگرمی :" . $fun . "<br />" . "kind : " . $kind . "<br />" . "device " . $device . "<br />" . "اثیر بر درس" . $study . "<br />" . "کنترل " . $agree . "<br />");
fclose('/1.txt');
}
do note that there is an "else" that includes all the aforementioned input fields that I used in the code , and that I am executing on localhost.
thanks
You cannot write to it since you are opening it as read-only:
$handle = fopen('/1.txt', "r");
Instead:
$handle = fopen('/1.txt', "w"); // to write only, if you need to read and write use 'w+'
You also need to store fopen in a $handle so you can write to it later.
Documentation: http://www.php.net/manual/en/function.fopen.php
Now the first parameter for fwrite should be $handle:
fwrite($handle, "hour :" . $hour . "<br />" . "family" . $family . "<br />" . "تطابفق با درس" . $how . "<br />" . "سرگرمی های غیر مجازی : " . $will . "<br />" . "نوع سرگرمی :" . $fun . "<br />" . "kind : " . $kind . "<br />" . "device " . $device . "<br />" . "اثیر بر درس" . $study . "<br />" . "کنترل " . $agree . "<br />");
Documentation: http://www.php.net/manual/en/function.fwrite.php
At the end you should also close with $handle:
fclose($handle);
Documentation: http://www.php.net/manual/en/function.fclose.php
You are opening the file as read-only, with the ruse w instead. And you need to pass fwrite the return of fopen as first argument, not the filename:
$f = fopen('/1.txt', "w");
fwrite($f,"hour :" . $hour . "<br />" . "family" . $family . "<br />" . "تطابفق با درس" . $how . "<br />" . "سرگرمی های غیر مجازی : " . $will . "<br />" . "نوع سرگرمی :" . $fun . "<br />" . "kind : " . $kind . "<br />" . "device " . $device . "<br />" . "اثیر بر درس" . $study . "<br />" . "کنترل " . $agree . "<br />");
fclose($f);
You have to pass in a 'w' to write to a file.
$handle = fopen('/1.txt', "w");
Passing in 'r' makes it so you are opening a 'read-only' file.
Much simpler:
file_put_contents('/1.txt', $text);

Categories