PHP - Display Table If Variable Is Set
Hi, i cant seem to get something working, should be simple but its not working for me.
I just need to only display a table if a variable in my table = a certain value. The column in the table is called 'option1_available' and if its value is set to 'Y' i want it to display a table. Appreciate any help, Thanks Similar TutorialsI'm trying to display an html <div> based on the state of a variable set during php execution . The variable is $chk and is set to either 0 or 1 with 0 meaning failed and 1 meaning pass. Here's the code: if <?php echo "{$chk}";?> == 0 <div class="container"> <div class="row" style="color:red"> <br><br><br><br><br><br> <center>Database Update Failed</center> </div> </div> else <div class="container"> <div class="row"> <br><br><br><br><br><br> <center>Database Updated</center> </div> </div>
Thanks in advance, Larry Edited June 19, 2020 by larry29936additioal info So I have these session variables being stored on login. Each page stores these session variables in local PHP variables. For some reason, all pages display that variable in the URL except one page. I have done some 'echo' work just to ensure variables have values stored and that everything was being read appropriately, no issues there. The variables are apparent everywhere on the page besides the URL. Below you can find all the code I have to make this thing work....maybe someone can point me in the right direction because I am STUMPED!!! LOL So my first page calls a popup window in javascript defined below. The link involves the following PHP Code: [Select] $customer_id = $_SESSION['cid']; $customer_email = $_SESSION['cust_email']; $customer_fname = $_SESSION['cust_first_name']; $customer_contact_id = $_SESSION['customer_contact_id']; $customer_company_id = $_SESSION['customer_company_id']; $c_project_id = $_GET['pid']; $c_project_id = mysql_real_escape_string($c_project_id ); $c_project_id = eregi_replace("`", "", $c_project_id); Then comes in the Javascript... Code: [Select] <script type="text/javascript"> <!-- $(document).ready(function(){ $(".approval").click(function(){ v = $(this).attr("id"); url = 'deny_approval.php?cid=<?php echo "$customer_id"; ?>&company_id=<?php echo "$customer_company_id"; ?>&customer_contact_id=<?php echo "$customer_contact_id"; ?>&pid=<?php echo "$customer_project_id"; ?>§ion=' + v; window.open(url, "myWindow", "status = 1, toolbar = no, scrollbars = yes, location = no, resizable = no, height = 600, width = 600, resizable = 0" ); }); }); //--> </script> And finally, the HTML.... Code: [Select] <body> <a href="#" id="deny_quote_approval" class="approval">Deny Quote Approval</a><br /><br /> </body> Any ideas?? As always, any help would be greatly appreciated. Bl4ck Maj1k I want to retrieve an image id from a db and show the images. I cant get the syntax right for the image tag.Any help appreciated. Code: [Select] function display_covers() { global $wpdb; $query = "select * from wp_cover"; $result = mysql_query($query)or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); echo mysql_error(); if (!$result) return false; echo'<div class="wrap"><p>choose from one of the covers below</p></div>'; echo'<div id="main">'; echo'<table class="main" cellpadding="2">'; //echo"<caption>Please choose a book cover</caption>"; ?> <thead><tr><td colspan="5" ><h6 class="main">Book Covers</h6></td></tr> </thead> <?php $i=0; $size=3; echo "<tbody>"; echo "<tr>"; while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { /* display picture */ ?> <td class="main"> <?php echo"<img src="/Applications/MAMP/htdocs/wordpress_3/wp-content/plugins/Authors2/jackets/"{.$row['pix'].}""/>"; echo"</td>"; $i++; if($i==$size) { echo "</tr><tr>"; $i=0; } } } This is my code Code: [Select] $file = $file . $line; fclose($fh); echo "<script language= 'JavaScript'>alert(' . $file . ');</script>"; the alert box is not coming up. Please suggest a way to print the contents of the file in a alert box. Using Javascript, how do I do an alert and show the value of a variable? thanks I am building a website that uses session variables extensively. The site is getting a little complicated, and I am starting to lose track of which session variables are assigned, and what their values are. Is there some way where I can create a piece of code that will display all of the existing session variables and their values? Trying to figure out how to make it so name is a link to the profile when its echo anyone know how to do this? im at a huge stand still Code: [Select] <?php $sql = "SELECT name FROM users WHERE DATE_SUB(NOW(),INTERVAL 5 MINUTE) <= lastactive ORDER BY id ASC"; $query = mysql_query($sql) or die(mysql_error()); $count = mysql_num_rows($query); $i = 1; while($row = mysql_fetch_object($query)) { $online_name = htmlspecialchars($row->name); echo '<a href="Inbox.php">"'[$goauld]'</a>"'; ?> I am attempting to us glob to display contents of a users folder using a session variable. Example: I have a session variable called department Code: [Select] $row_fullname['department']; In department I have the name of the department the user belongs to such as: office, plant, maintenance, and groundskeeping I created a folder called docs inside of docs there are 4 subfolders called office, plant, maintenance, and groundskeeping I found this code which will display the contents of the folder: Code: [Select] <?php $files = glob( './docs/office/*.*' ); foreach ( $files as $file ) { echo '<a href="./docs/office/' . basename( $file ) . '"target="_blank">' . basename( $file ) . '</a><br />'; } ?> The above code works fine, but I would like it to only display the contents of a departments folder only if the user is part on that department. Here is an example that I know is completely wrong but it may help explain what I am trying to do. Code: [Select] <?php ]<?php $files = glob( './docs/echo $row_fullname['department'];/*.*' ); foreach ( $files as $file ) { echo '<a href="./docs/echo $row_fullname['department'];/' . basename( $file ) . '"target="_blank">' . basename( $file ) . '</a><br />'; } ?>Thanks for your time Hey, I have a mysql table for my setups, it contains basically three fields: 'id','variable','value'. i want to create/name a variable from a result from the database and then from another field it should give the newly created variable its value The table is already filled with the variables i want to use, now i just want my index page to get the different variable out of the table with the value as its value. Is that even possible? so lets say i have a variable in my table called 'header_color' the value in that table row is 'FFF' i want my index to get all variable from the database (through a while??) with again its value as a value. This is my thought: $sql = mysql_query("SELECT * FROM setup"); while ($res = mysql_fetch_array($sql)){ $res[variable]; = $??my_variable??; $myvariable = $res[value]; } and so when i have my div for my header i want it to be <div style="background-color:#<?=$header_color?>"> resulting in <div style="background-color:#FFF> in my table under variable it has the name "header_color" and under value "FFF" maybe i need to create an array or something i have no idea. Hope you guys can help me. i have a stupid simple problem here, but ive never done this exactly this way before and im having a tough time working it out. was looking for any suggestions. my script is working fine: $table_name = "plan"; $sql = "SELECT id, plan_name FROM $table_name ORDER BY plan_name"; $query = mysql_query($sql); if(mysql_num_rows($query) > 0) { echo "<table>"; while($row = mysql_fetch_array($query)) { echo "<tr><td>" . $row['plan_name'] ."</tr></td>"; } echo "</table>"; ... but i have another table company that are related to plan_name i have the company_id field in my plan table for the relationship. and that id is related to the company id field of course. all i am trying to do is display the company_name next to $row['plan_name'], so i know which plans are related to which company. i think i need to create two seperate queries, but is there a way to include everyone in one query? is there a better way? here is my sql: plan table: `id` int(11) NOT NULL AUTO_INCREMENT, `company_id` int(11) NOT NULL, `plan_name` varchar(255) NOT NULL, ... company table `id` int(11) NOT NULL AUTO_INCREMENT, `plan_id` int(11) NOT NULL, `company_name` varchar(255) NOT NULL,... it also seemed to be overkill to have two while loops running.. i am just thinking out loud on the best approach to this. Hi guys,
I've got the following command im trying to push out how it would look if i ran it in ssh
<?php if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist"); if(!($con = ssh2_connect("hostname", 22))){ echo "fail: unable to establish connection\n"; } else { if(!ssh2_auth_password($con, "username", "password")) { echo "fail: unable to authenticate\n"; } else { echo "okay: logged in...\n <br>"; if (!($stream = ssh2_exec($con, "showspace" ))) { echo "fail: unable to execute command\n"; } else { stream_set_blocking($stream, true); $data = ""; while ($buf = fread($stream,4096)) { echo $data .= $buf; } fclose($stream); } } } ?>This displays as: ---Estimated(MB)---- ---Estimated(MB)---- RawFree UsableFree ---Estimated(MB)---- RawFree UsableFree 135770112 67885056 in putty it displays as: TestRepo cli% showspace This may be in here already and I'm sorry for not being able to find it but.. I just want to display some information that I get from the database in a HTML table only using 2 columns. Do I just set i=1 and run a if statement to see what column I am on? like Code: [Select] $i =0 While ($row = msyql_fetch_array($result)) { if ($i==0) { // start a new row echo "<tr>"; $i = $i++; }else{ //columns echo "<td>info</td>"; $i=$i++; } if ($i < 2) { //end the row reset $i echo "</tr>"; $i =0; } } Or something like that, am I heading in right direction? Thanks Stephen Hey everyone, I have a problem here.Now as u see my data is being displayed one after another in vertical manner.But what do i want to do is the entire table being displayed in same page continuously one after another in horizontal manner.how would i do that? (below a screen shot is given how my table looks like.) <code> <?php for($i=0;$i<=25;$i++) { if($i%5==0) { ?> <table> <tr> <th scope="row">U_Id :</th> <td><?php echo 'uid'; ?></td> </tr> <tr> <th scope="row">Name :</th> <td><?php echo "name"; ?></td> </tr> <tr> <th scope="row">Teamname :</th> <td><?php echo "teamname"; ?></td> </tr> <tr> <th scope="row">Coins :</th> <td><?php echo 'coins';?></td> </tr> <tr> <th scope="row">Cash:</th> <td><?php echo 'cash'; ?></td> </tr> </table> <br/> <?php //echo "$i<br/>"; } } ?> </code> I have a dropdown menu <td width="148" height="35" valign="top"><b>Type: </b> </td> <td><select name ="tabledrop"> <option value="goggles">goggles</option> <option value="headbands">headbands</option> <input type='hidden' id='tabledrop' name='tabledrop' value = ''/> </select> </td> those 2 options are actually names of my tables. I tried this and got some syntax error. $type = $_POST['tabledrop']; $item = $_POST['goggles_name']; $price = $_POST['goggles_price']; $file = $_FILES['goggles_image']['name']; $query = "INSERT into $type SET [$type]_name = '$item' , [$type]_price = '$price' , [$type]_image = '$file'"; Hello, I'm working on a PHP register form, all I want to do, is to be able to insert an extra variable into the database: Code: [Select] // now we insert it into the database $insert = " INSERT INTO users (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."') "; $add_member = mysql_query($insert); right, so I have the username and password variable being passed. But I also want to pass a variable into a column called 'weaponAttachments', all I want for this variable to be is 5000. So, in other words, something like this: 5000['weaponAttachments'] Thanks Hi, I'm trying to drop a table form a database using the table name as a variable. This variable is set within a session. I am using a form where you input the table name, then the DROP TABLE procedure is executed in the next page. I know that the variable gets passed because it prints the table name variable out when I "echo". The execution is simple (code found in deletetable.php) $temp = $_POST['temp']; $query = "DROP TABLE $temp"; if(mysql_query($query)){ echo "<h1 style='color:green;'>Table $temp deleted</h1>";} else{ echo "<h1 style='color:red;'>Deletion of table '$temp' failed!</h1>";} Here's my code for the two pages: delete_table.php <?php include("includes/header.html"); session_start(); $hostname = $_SESSION['hostname']; $user = $_SESSION['user']; $passwd = $_SESSION['passwd']; $database = $_SESSION['database']; $tblname = $_SESSION['table']; $conn = mysql_connect($hostname, $user, $passwd, $database); /*if(! $conn ) { die('Could not connect: ' . mysql_error()); }*/ ?> <div id="container"> <div id="header">Create DB</div> <div id="breadcrumbs"> <?php function check_port($port) { $conn = @fsockopen("127.0.0.1", $port, $errno, $errstr, 0.2); if ($conn) { fclose($conn); return true; } } function server_report() { $report = array(); $svcs = array('3306'=>'MySQL'); foreach ($svcs as $port=>$service) { $report[$service] = check_port($port); } return $report; } $report = server_report(); ?> <div id="server"><p>Server is <?php echo $report['MySQL'] ? "running" : "offline"; ?></p></div> <?php if(!$_SESSION['hostname']){ echo "<font color='red'>Not connected to server!</font>"; } else { echo "<font color='green'>Server: ".$_SESSION['hostname']."</font>"; } if(!$_SESSION['database']){ echo ""; }else{ echo "<br><font color='green'>Database: ".$_SESSION['database']."</font>"; } ?> </div> <div id="nav"> <p><a href="#" onclick="javascript:window.open('connect_db.php','_self');"><img src="server_conn_ico.png" align="left" />Server Connection</a></p> <p><a href="databases.php"><img src="databases_ico.png" align="left" />View Database</a></p> <p><a href="create_db.php"><img src="server_folder_ico.png" align="left" />Create Database</a></p> <p><a href="drop_db.php"><img src="drop_ico.png" align="left" />Drop Database</a></p> <p><a href="create_table.php"><img src="status_ico.png" align="left" />Add Table</a></p> <p><a href="add_fields.php"><img src="server_ico.png" align="left" />Add Fields</a></p> <p class="active"><a href="delete_table.php"><img src="status_delete_ico.png" align="left" />Delete Table</a></p> <p><a href="view_tables.php"><img src="user_admin_ico.png" align="left" />View Tables</a></p> <p><a href="view_data.php"><img src="user_admin_ico.png" align="left" />View Table Data</a></p> <p><a href="http://localhost/phpmyadmin/" target="_blank"><img src="phpmyadmin_ico.png" align="left" />phpMyAdmin</a></p> <p><a href="connect_info.php"><img src="health_ico.png" align="left" />System Info</a></p> <p><a href="error_log.php"><img src="logs_ico.png" align="left" />Server Log</a></p> <p><a href="bug_report.php"><img src="bugs-icon.png" align="left" />Bug Reports</a></p> </div> <div id="controls"><a href="javascript:self.close()"><img src="controls.png" /></a></div> <div id="main"> <div id="content"> <!--<h1>Delete Database Table</h1>--> <?php if(empty($database)) { echo "<p>You must be connected to a database in order to delete a table.</p>"; }else{ //echo 'Connected successfully to \''.$database.'\''; // Check tables $sql = "SHOW TABLES FROM $database"; $result = mysql_query($sql); if (mysql_num_rows($result) > 0) { echo "<p style='text-align:left;padding-left:24px;'>Available tables:</p>\n"; echo "<pre style='text-align:left;padding-left:24px;font-size:1.2em;'>\n"; while ($row = mysql_fetch_row($result)) { echo "{$row[0]}\n"; } echo "</pre>\n"; } ?> <form action="deletetable.php" method="post"> Enter table you'd like to delete from '<?php echo $database; ?>' database: <input name="temp" type="text" /><br/> <input name="Submit" type="submit" value=" Delete Table " /> <input type='button' value=' Cancel ' onclick="javascript:window.location='connect_db.php';"></p> </form> <?php } include("includes/footer.html"); ?> Executing file deletetable.php: <?php include("includes/header.html"); session_start(); $hostname = $_SESSION['hostname']; $user = $_SESSION['user']; $passwd = $_SESSION['passwd']; $database = $_SESSION['database']; //$tblname = $_SESSION['table']; $conn = mysql_connect($hostname, $user, $passwd, $database); ?> <div id="container"> <div id="header">Create DB</div> <div id="breadcrumbs"> <?php function check_port($port) { $conn = @fsockopen("127.0.0.1", $port, $errno, $errstr, 0.2); if ($conn) { fclose($conn); return true; } } function server_report() { $report = array(); $svcs = array('3306'=>'MySQL'); foreach ($svcs as $port=>$service) { $report[$service] = check_port($port); } return $report; } $report = server_report(); ?> <div id="server"><p>Server is <?php echo $report['MySQL'] ? "running" : "offline"; ?></p></div> <?php if(!$_SESSION['hostname']){ echo "<font color='red'>Not connected to server!</font>"; } else { echo "<font color='green'>Server: ".$_SESSION['hostname']."</font>"; } if(!$_SESSION['database']){ echo ""; }else{ echo "<br><font color='green'>Database: ".$_SESSION['database']."</font>"; } ?> </div> <div id="nav"> <p><a href="#" onclick="javascript:window.open('connect_db.php','_self');"><img src="server_conn_ico.png" align="left" />Server Connection</a></p> <p><a href="databases.php"><img src="databases_ico.png" align="left" />View Database</a></p> <p><a href="create_db.php"><img src="server_folder_ico.png" align="left" />Create Database</a></p> <p><a href="drop_db.php"><img src="drop_ico.png" align="left" />Drop Database</a></p> <p><a href="create_table.php"><img src="status_ico.png" align="left" />Add Table</a></p> <p><a href="add_fields.php"><img src="server_ico.png" align="left" />Add Fields</a></p> <p class="active"><a href="delete_table.php"><img src="status_delete_ico.png" align="left" />Delete Table</a></p> <p><a href="view_tables.php"><img src="user_admin_ico.png" align="left" />View Tables</a></p> <p><a href="view_data.php"><img src="user_admin_ico.png" align="left" />View Table Data</a></p> <p><a href="http://localhost/phpmyadmin/" target="_blank"><img src="phpmyadmin_ico.png" align="left" />phpMyAdmin</a></p> <p><a href="connect_info.php"><img src="health_ico.png" align="left" />System Info</a></p> <p><a href="error_log.php"><img src="logs_ico.png" align="left" />Server Log</a></p> <p><a href="bug_report.php"><img src="bugs-icon.png" align="left" />Bug Reports</a></p> </div> <div id="controls"><a href="javascript:self.close()"><img src="controls.png" /></a></div> <div id="main"> <div id="content"> <?php $temp = $_POST['temp']; $query = "DROP TABLE $temp"; if(mysql_query($query)){ echo "<h1 style='color:green;'>Table $temp deleted</h1>";} else{ echo "<h1 style='color:red;'>Deletion of table '$temp' failed!</h1>";} include("includes/footer.html"); ?> Your help is greatly appreciated!! <?php function money($amount,$separator=true,$simple=false){ return (true===$separator? (false===$simple? number_format($amount,2,'.',','): str_replace('.00','',money($amount)) ): (false===$simple? number_format($amount,2,'.',''): str_replace('.00','',money($amount,false)) ) ); } $income = 5000000000; $daily = money($income*24,true,true); $weekly = money(($income*24)*7,true,true); $monthly = money((($income*24)*7)*30,true,true); ?> </center> <center> <table border="1"> <tr> <td>Daily</td> <td><?php echo $daily ?></td> </tr> <tr> <td>Weekly</td> <td><?php echo $weekly ?></td> </tr> <tr> <td>Monthly</td> <td><?php echo $monthly ?></td> </tr> </table> </form> </center> What am I doing wrong? Im fairly new to this How to display items like bottom table?
And here is the code
<? print" <table style=\"width:100%\" class=\"tableList\"> <tr> <th style=\"width:35%\">Prize Name</th> <th style=\"width:12%\">Amount</th> <th style=\"width:12%\">Points</th> <th style=\"width:12%\">Available</th> <th style=\"width:12%\">Redeemed</th> <th style=\"width:17%\">Action</th> </tr>"; $giftCardQuery = 'SELECT currency, amount, pointsPrice, instant_gift_cards.id, instant_gift_cards.giftCardName, instant_gift_cards.giftCardImage FROM instant_gift_card_codes INNER JOIN instant_gift_cards ON (instant_gift_card_codes.giftCardId = instant_gift_cards.id) WHERE instant_gift_cards.status = :cardStatus ORDER BY instant_gift_cards.dateCreated DESC'; $giftCard = $db->prepare($giftCardQuery); $giftCard->bindValue(':cardStatus', 'Enabled', PDO::PARAM_STR); $giftCard->execute(); if($giftCard->rowCount() > '0'){ while($giftCardRow = $giftCard->fetch(PDO::FETCH_ASSOC)){ $giftCardsAvailableQuery = 'SELECT count(*) FROM instant_gift_card_codes WHERE currency = :currency AND amount = :amount AND pointsPrice = :pointsPrice AND giftCardId = :id AND status = :status'; $giftCardsAvailable = $db->prepare($giftCardsAvailableQuery); $giftCardsAvailable->bindParam(':currency', $giftCardRow['currency'], PDO::PARAM_STR); $giftCardsAvailable->bindParam(':amount', $giftCardRow['amount'], PDO::PARAM_STR); $giftCardsAvailable->bindParam(':pointsPrice', $giftCardRow['pointsPrice'], PDO::PARAM_STR); $giftCardsAvailable->bindParam(':id', $giftCardRow['id'], PDO::PARAM_INT); $giftCardsAvailable->bindValue(':status', 'Available', PDO::PARAM_STR); $giftCardsAvailable->execute(); $gCardsAvailable = $giftCardsAvailable->fetch(PDO::FETCH_COLUMN); $giftCardsRedeemedQuery = 'SELECT count(*) FROM instant_gift_card_codes WHERE currency = :currency AND amount = :amount AND pointsPrice = :pointsPrice AND giftCardId = :id AND status = :status'; $giftCardsRedeemed = $db->prepare($giftCardsRedeemedQuery); $giftCardsRedeemed->bindParam(':currency', $giftCardRow['currency'], PDO::PARAM_STR); $giftCardsRedeemed->bindParam(':amount', $giftCardRow['amount'], PDO::PARAM_STR); $giftCardsRedeemed->bindParam(':pointsPrice', $giftCardRow['pointsPrice'], PDO::PARAM_STR); $giftCardsRedeemed->bindParam(':id', $giftCardRow['id'], PDO::PARAM_INT); $giftCardsRedeemed->bindValue(':status', 'Redeemed', PDO::PARAM_STR); $giftCardsRedeemed->execute(); $gCardsRedeemed = $giftCardsRedeemed->fetch(PDO::FETCH_COLUMN); if($giftCardRow['giftCardImage']){ $nameOrImage = '<img src="./images/giftcardrewards/'.$giftCardRow['giftCardImage'].'" alt="'.$giftCardRow['giftCardName'].'" title="'.$giftCardRow['giftCardName'].'">'; }else{ $nameOrImage = $giftCardRow['giftCardName']; } if($gCardsAvailable == '0'){ $redeemAction = 'Out of Stock'; } elseif($userInfo['currentPoints'] < $giftCardRow['pointsPrice']){ $needed = $giftCardRow['pointsPrice'] - $userInfo['currentPoints']; $redeemAction = 'You need '.$needed.' point(s)'; } elseif($userInfo['currentPoints'] >= $giftCardRow['pointsPrice']){ $redeemAction = '<input type="button" value="Redeem" onclick="if(confirm(\'Are you sure to redeem this prize?\')){location.href=\'index.php?do=instantGiftCards&action=redeem&cardId='.$giftCardRow['id'].'&amount='.$giftCardRow['amount'].'\';}">'; } print" <tr> <td>".$nameOrImage."</td> <td style=\"text-align:center\">".$giftCardRow['currency'].$giftCardRow['amount']."</td> <td style=\"text-align:center\">".$giftCardRow['pointsPrice']."</td> <td style=\"text-align:center\">".$gCardsAvailable."</td> <td style=\"text-align:center\">".$gCardsRedeemed."</td> <td style=\"text-align:center\">".$redeemAction."</td> </tr>"; } }else{ print" <tr> <td colspan=\"4\" style=\"text-align:center;color:#2B1B17;padding:15px 0\">No prizes added.</td> </tr>"; } print" </table>"; ?> Hi I have the following code: Code: [Select] $result = mysql_query("SELECT * FROM xbox_games order by gameid"); $row = mysql_fetch_assoc($result); $id = $row["gameid"]; $title = $row["gametitle"]; $cover = $row["cover"]; <?php echo $title;?> Which displays only the first result from my database. How can i change this to display all the results either as a list, or in a table? Thanks I have the code below displaying images and image names. I want these to display in a table 2 rows high by the needed number of columns to show all the images in the directory. I have no idea what to do. What I am getting now is a single column with each image in its own row. <?php $path = "./uploaded/"; $dir_handle = @opendir($path) or die("Unable to open folder"); while (false != ($file = readdir($dir_handle))) { if($file == "index.php") continue; if($file == ".") continue; if($file == "..") continue; //show in a table 2 rows by required/needed number of columns echo'<div>'; echo '<table border="1">'; echo "<img src='$path/$file' alt='$file'>"."<img src='$file' alt='$file'>"; echo'</table>'; echo '<div>'; } ?> |