Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Selective Echoing And Database Select


I have written a search engine for business listings for the company I work for. Each listing is in a database, and that works fine. The problem though is two-fold.

The first part of the problem is that not all listings utilise every column of the database, and this leaves gaps when echoing the results. This is not what i had in mind, Any ideas/help would be appreciated.

The second part of the problem is related to the first in that there is a link for any listing that has a website, but not every listing has a website, so every listing having a "Visit our Site" link is impractical and shoddy. Also, i'm not sure how to echo the url from the database effectively in the first place.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Echoing PHP Code From A Database?
I have the following data in a MySQL database:
<a href="<?php echo $server; ?>Sugapablo-Stick_It_To_The_Man.mp3"

let's call it $row[0].

when I echo $row[0], the php code is shown as opposed to the value of
$server.

How can I get the value of $server to appear? str_replace?

SELECT Error: No Database Selectedin Query: SELECT * FROM Schedule
I got the above error message after reading FAQ #10 which applied to my first error. The thing is, I thought I had selected a database. This script is copied from a tutorial, and I'm just too new at this to spot my error. PHP Code:

Selective Replacements
I have this in one of my scripts to take out line breaks:
$html=str_replace(array("
","
"),"",$html);

Now I would like to leave some line breaks.
For example, if $html has something like this:
"<textarea> default text
with line
breaks </textarea>"

Selective Form Data Processing
I have *quite a bit* of form fields for a certain form that needs to be eMailed. The problem is that when completely filled out, there is quite a bit of information to be emailed. How would I go about telling the PHP to ignore any forms that are not filled out -- letting it process less code? If this helps, the coding for the page that does the actual processing is: Code:

Selective Permission To Write In The Directory.
I want to create a publicly accessible php page which will generate
images (with the GD library) and store them in some directory. For
this I have to change the permission of directory (it has to be
writable for everybody). However, as far as I understand, this will
allow everybody to put in the directory whatever files. I would like
that only my php program has permission to write to the directory. Is
there any possibility to do that?

Selective Rendering Of Part Of A Page
I want to skip the rendering of certain parts of a Web page if the
user doesn't have a certain permission (e.g. a cookie). I'd like to do
it along these lines:

<p>Anybody can see this paragraph.</p>
<? start_protected_section($got_permission); ?>
<p>Not everybody can see this paragraph.</p>
<? end_protected_section(); ?>

Is it possible to disable the rendering of a section outside the code
like this (perhaps by setting a PHP flag to redirect subsequent
output)? I don't really want to complicate things by moving part of
the page into a separate "include file" or mixing the HTML and PHP by
using a here-document (the <<<END syntax).

Database Value Select In Combo Box!
This function is intended to display the current database field value as selected.. along with other values as general options.

I can't figure out how to get it work. Help is appreciated!!

function retrieve_category()
{
$cat = mysql_query("SELECT category_id FROM category");
while ($current_row = mysql_fetch_row($cat))
{
$row = $current_row[0];
if ($row == $id)
{
printf("<option selected>%s</option>
",$current_row[0]);
}
else
{
printf("<option>%s</option>
",$current_row[0]);
}
}
}

Populating A Select Box From A Database
I have a subscription database that allows you to edit a subscribers data. For example, you enter a search term like "Bob" and it returns a list of everyone named Bob. You click the one you want and it goes to a subscriber detail page, where all of his data is populated to a form. You can directly edit this form and click save to overwrite it.

The only issue is the select boxes (drop downs) - say I have four options in the drop down box, red, blue, green and black. On my details page for bob I end up with five, I have those four PLUS whatever was saved for his color, so it shows up twice. If Bob is green, my select box looks like:

Green
Red
Blue
Green
Black

How can I make it so that Green only shows up once?

Select One Record From A Database
I am trying to select one record from a database. This databse has like 10 tables. I do not know which table this record is in. What php and mysql syntax would I use to accomplish this?

Randomly Select From Database?
this might seem like a stupid question, i should be able to do this. but on the front page of my site i want a thing to show a few users. but i dont want it to show the same people over and over. i want it to select different people each time. any ideas?

Editing Mysql Database Row With Select Box
I have a small site, this small site has a few categories, now I can add items through my online admin area fine and delete them fine, but when it comes to editting them I am having some trouble, everything is working fine except the category column, because it is a drop down box I do not know how to have the category selected during the creation progress selected all the other info is loaded.

Multiple Select From Database Where Clause
I have a website with a database full of category names...I want to be able to chose lets say 5 of these categories and use a select from database clause where I could simply enter the category names I want to use but am not sure how I would go about doing it.

I can get the list to display just the Aprilia category using the code below:

$data1->q("SELECT * FROM categories WHERE cat_name = 'Aprilia' ORDER BY cat_name asc");

However...how could I get my site to display Aprilia, Ducati, Honda, Suzuki, Yamaha?

Using PHP And MYSQL To Select From Database Using Images
I'm trying to update a main page with a list of details matching a selection from a display of images that are displayed in a small window that have been selected from an image group using a select box in the main window, however I don't know how to do this and the main page is not receiving anything when clicking on an image so it's refreshing with empty data. 

I've seen many many pages giving examples of how to do this with select boxes or how to do this if only one entry uses an image shown in the small window, but the image display window is displaying many different small images not a select box and the database itself has multiple entries that use the same image.  Can anyone help?  I have a few instant chat programs if someone wishes to discuss this with me in real-time to see what it is I'm trying to achieve.

Tick Box, Select And Update Database.
I am trying to change the value in table with a tick box. If the tick box is selected it changes the value in the field to 'y' and if it is not selected it changes the field to 'n'.

First of all I need to bring back the current state of the field and then I need to be able to update it from 'y' to 'n' as many times as I want. Code:

Population Select Menu Using Php And Database Values
I have no idea how to go about this. so i would apreciate some help i want to populate the values in a html select menu from database values in one table

so i want all the values from 1 particular field in the database to be displayed in the select menu as separate options.

Displaying A List Of Categories From A Database In A Select Box
Could someone please tell me why this outputs nothing

<select name=categories>
<?
$cat_array = get_categories();
foreach($cat_array as $this_cat)
{
echo "<option value="";
echo $this_cat["category_id"];
echo """;
echo ">";
echo $this_cat["category_name"];
echo "
";
}
?>
</select>

==========================================================

function get_categories()
{
//get the list of categories from the database

$conn = mysql_pconnect("localhost", "user", "pwd");
$query = "select * from categories";
$result = mysql_query($query);
if(!$result)
return false;

$num_cats = mysql_num_rows($result);
if($num_cats == 0)
return false;

$result = db_result_to_array($result);
return $result;
}

//A function that returns a query to the database as an array
function db_result_to_array($result)
{
$res_array = array();
for($count=0; $row=@mysql_fetch_array($result); $count++)
$res_array[$count] = $row;

return $res_array;
}

Connecting Two Database Populated Select Menus
I am able to grab the data from the database to populate the menus individually using.
PHP Code:

Select Specific Phrase From MYSQL Database
I am working on a World of Warcraft guild's website and I am trying to create a page where players can select different kinds of gear, i.e. the gear with the most Stamina.

All the player's items are stored in the database and every item have a field in the Items-table containing the item's tooltip. This could look something like:

Boots of the Nexus Warden
Soulbound
Feet Cloth
97 Armor
+27 Stamina
+17 Intellect
Durability 35 / 35
Equip: Improves spell hit rating by 18.
Equip: Increases damage and healing done by magical spells and effects by up to 21.

I then want to select the item with i.e. the most Stamina for all the different slots; Head, Chest, Legs etc.

If I write this:
$query = mysql_query("SELECT substring(item_tooltip, LOCATE('Stamina', item_tooltip)) AS maxor FROM roster_items WHERE member_id = &#3962;'") or die(mysql_error());

It returns the following:
Stamina +17 Intellect Durability 35 / 35 Equip: Improves spell hit rating by 18. Equip: Increases damage and healing done by magical spells and effects by up to 21.

But I want for it to show the leading characters also (in this case "+27 " before "Stamina") and then not show anything else after the phrase "Stamina". So it shows "+27 Stamina" and nothing else for the above mentioned item. How do I accomplish this?

And then, secondly how do I then get it to show only the item with the most Stamina after it selected the above?

Hope this makes any sense.

I've tried to search these forums and found something a little along the lines of my problem but haven't been able to adjust them to my needs and I therefore need your help which will be greatly appreciated.

Reusing An Object For Common Select To Database
I've noticed that after I finished this app, I had repeated a similar task over and over and would like to modularize it. The repeated task was connecting to the database, executing a select, putting all the results of the columns into different variables of an object. PHP Code:

Simple Filter Of Database With $_GET And Select SQL
I need help with my logic statement with a simple search engine on a MySQL table.
I have three form text input fields named f_name, l_name and dept. I am using the GET method to gather data the user enters in each input field.

So far I have been able to build a check to see that the submit has been clicked but I am having trouble with assembling the SQL statement because I need for the search engine to be able to filter the results based on the information provided in 1-3 of the fields.

I could use if statements with some and clauses but that would mean that I would have to account for each combination. Something like

If(($_GET[‘f_name’] != “”) || ($_GET[‘l_name’] !=) || ($_GET[‘dept] !=)){

$sql = "SELECT * FROM facform WHERE f_name LIKE '$_GET[f_name]',
l_name LIKE '$_GET[‘l_name]', dept LIKE '$_GET[dept]' ”;}

The problem with this is that I would have to get every combination and it’s not very scalable. How can I create this SQL statement dynamically? Code:

Error In Generating Table From Database Select Statment
I am trying to dynamically create a table with the results from a select statement. Below is the code that is not working. Any help would be oh so greatly appreciated. This is for a final at school which is due in an hour. This is the only thing I can't seem to make work. Code:

Select Specific Snippet Of Text, Replace With A Database Result
I'm having some problems trying to do something; I just can't think of a way to do it. Basically, I want to search for a specific snippet of text in a body of text, then replace it with the requested database result with some thrown in HTML.

Users will be able to type the following (or something along these lines, depending on what works best): [image=12345]Insert caption here[/image]

Then I need it to search for the requested image in the appropriate table and return the image's url (for an example, let's say the table is called "images", and the columns required are "imageid" and "imageurl". Code:

Echoing Sql
Another good thing to do would be to set the sql statement equal to a variable instead of just inside of the mysql_query() function. PHP Code:

Can A "selective" Table UPDATE Be Done?
i have a table with a column of data type smallint. how could i increase that number that's stored in the smallint by 1...only when certain pages or conditions are meet, in other words...an autoincrement is not wanted here because i don't want to increase that # by one each and every time the table is updated (for other columns).

is it possible to do an UPDATE (with a ++ on the column) on the table w/o first doing a SELECT to get the present number?

Echoing Image
form action="index.php#order" method="post" name="image1" id="image1">
<input name="image1" type="submit" id="image1" value="Buy!">

form action="index.php#order" method="post" name="image2" id="image2">
<input name="image2" type="submit" id="image3" value="Buy!">

<form name="form1" method="post" action="thankyou.php">

<?php
if ($_POST[image1]) {
echo "<img src="image/image1.jpg">";
}
if ($_POST[image2]) {
echo "<img src="image/image2.jpg">";
}
?>

Problem Echoing
If I set a varaible as

$EOL = "
"

But then want to echo that to a HTML page to see the above string
i.e.

by doing: echo($EOL);

How do I do it?

I've tried quotemeta, addslashes and htmlspecialchar
but can't seem to work it out.

Echoing An '&' Character?
I'm trying to figure out how to include an '&' character in a php echo. I'm not looking for the html & a m p ; special character, but the actual character, since i'm trying to do this: Code:

echo "<A HREF"/download.php?type=wallpaper&file=$filename">Download</A>";

instead it returns a link such as this: Code:

/download.php?type=wallpaperfile=wallpaper.zip

Echoing Php In A Textfield
when i echo out text from mysql in a text area field it also echoes out the line breaks e.g it doesn't happen if i echo out anywhere else on the page, could i do a preg_replace to make all the line breaks echo NULL? Code:

Echoing Codes
I have a simple script for an IFrame for my forum page...

<?php if(!isset($_GET['post'])){ echo '<iframe src="/forum/" name="fleet" width="800" height="auto" scrolling="no" frameborder="no" id="fleet"> Your browser does not support inline frames or is currently configured not to display inline frames. </iframe>'; }else{
 echo '<iframe src="/forum/viewtopic.php?p='.$_GET['post'].'" name="fleet" width="800" height="auto" scrolling="no" frameborder="no" id="fleet"> Your browser does not support inline frames or is currently configured not to display inline frames. </iframe>';} ?>

Whenever I open the page, it does not automatically expand to the framed page height, how can I fix this...?

Echoing Out A While In A Table
i use this while loop to echout all my categories at once, but is there a way i could have them echo out in a table say 5 across at a time? Code:

Echoing Value To List Menu
Hi, I was wondering can I echo out value from db to list menu and how?

Echoing Strings With Quotemarks?
I have a statement that gives me an error:

echo "<table><tr><td>Title</td><td>Author</td><td>Date added</td><td>Hits</td></tr><tr><td><a href="test">$arttitle</a></td><td>$artauthor (<a href=/"mailto:$artauthoremail/">)</td><td>$artcreationdate</td><td>$arthits</td></tr></table><br>";


Parse error: parse error, unexpected T_STRING, expecting ',' or '' in /home/hsphere/local/home/cmwong/singaporeanimenews.net/mm-article.php on line 299


backslashing the quotemarks continues giving the error. How might I get around this?

Echoing Variables Into HTML
So I'm playing with a very retarded list of products 1-9, and have the
following list.php page snippet excluding html header/footers/table tags:

Php/mysql Echoing Same Thing Twice--help!
I'm just learning php and set up a sample mysql db to practice with. I
have the following script and cannot for the life of me figure out why
it is printing each field of the row twice? I checked my db and it only
contains the entries once. What is causing this?!

-----------------------------------------------------------------------
<?php
$con_id = mysql_connect('localhost','dboard_mbr','pa1ss2wo3r d');

mysql_select_db('kp_dboard',$con_id);

echo join(mysql_fetch_array($thequery=mysql_query('sele ct * from
threads',$con_id)),' --- ') . '<br>'

echo join(mysql_fetch_array($thequery),' --- ') . '<br>'

echo join(mysql_fetch_array($thequery),' --- ');
?>
-----------------------------------------------------------------------

Strange Results Echoing '£'
I'm getting a very strange result trying to echo a simple pound sign '£'. Here's my code:

$currency = '£';
echo $currency;
For some reason it's outputting this:
£With the Â...

I've tried this as well: echo htmlentities($currency)but I get the same result.. I've never had this problem before and it doesn't6 happen with any other symbols, could anyone suggest an answer?

Echoing The Correct XML Tag Data
I am having trouble ECHOing specific data and for some reason the links for each sub parent are combined into one link...Let me explain that. The first link is correct and outputs http://example.com/1, but the second link outputs http://example.com/1http://example.com/2

Does anyone know why that is? The other problem I have is that I have about 200 sub parents in my xml file and the sub parents represent different categories, for example: Code:

Join And Echoing Correct Id
The information is displayed correctly.  The problem comes into play with the record id's. 

The link I would click on for the employees name is echoing the job id and not the employee id so I get sent to the job page and not the employee profile.  The link I would click on for the job is echoing fine. Code:

Echoing Multiple Arrays
I have a products table that I want to echo the results of 3 different categories, I can query the db just fine and get results for a single category, but I'm a newb to PHP and don't know the trick way to do slick recursion. Code:

Gathering Results And Echoing Them As One?
I'm trying to display all the results from a database and use echo them using $total.

$total =     do {  "".$row_use['lon']." ".$row_use['lat'].""  } while ($row_use = mysql_fetch_assoc($use));

echo $total;

I was wondering why does that not work?  How do I get the php repeated regions to work?

Echoing A Variable Which Isn't Set Until Later In The File?
I could have sworn this was possible somehow, but it isn't working for me... Let's say I have a line at the top of my file, which is echo "$links". Then, the variable $links is set further down in the file, depending on some SQL results and GET variables.

For me, even though I'm setting $links in the file, it will only echo if it's set before it's echoed. It make sense, but I have a definete memory that I once had a way around that problem - anyone know how to do it? Code:

Setting Headers And Echoing Images
My scenario is that I am trying to put an image on a page using php not on my server, that does not have php. I am using the tag <img src=http://myserver.com/asdf.php3> and asdf will a) read an image b) set a header("Content-type: image/gif") and c) echo the image. That works fine.
The problem is that I also wanted to include a link based on the image (ie - dynamic, involving php). After I set the header, regular tags are ignored and I can't echo anything before a header, nor can I set a different header.
SO my question is, does anyone know a workaround to this problem: like displaying an image on a non-server page, without setting a header, or a way to dynamical reference something? Any help is greatly appreciated and if you think you might be able to help, but don't understand my situation or need clarification, contact me.

PS - If it can't be done with PHP, can it be done with any other language anyone knows of?

Time - Echoing It Back Differently
I have a datetime column setup in a mysql database. My web host, which i based in Hawaii, has a different time zone to that of mine over her in good old England. I was wondering is there a way of echoing out the time from the datetime column but adding on 9 hours more?? Or even would it be easier to submit the data into the database with the time difference?

Echoing 3 Types Of Data From 1 Table Row
I have this script where one of the rows in a mysql table is named "type" tinyint(3).

now when a person joins the site they have a basic membership and their data is 0 in the type row when they become silver members it is 1 and gold is 2 all 3 numbers are entered into that one row for each member depending on what kind of membership they have.

what I want to do is echo each type of membership on a page by the total number of each type so say there is 100 basic memberships then it would add up all the 0's within the row in the mysql database and then echo that total. I have already gotten it to display total number of users by adding. Code:

$query = "select id from user";
$result = MYSQL_QUERY($query);
$totalusers=mysql_num_rows($result);
@mysql_free_result($result);
if(($s=="")or($s>=$totalusers)or($s<0)){
$s=0;}

and then having <?print $totalusers;?> where ever I want it to echo. How can I do the same with the memberships? I have a feeling that it would have something to do with $totalusers=mysql_num_rows($result); i need to change mysql_num_rows to something else?

Echoing Multiple Html Tables
im trying to echo out multiple results from a database and returning them in a table. Each new row in the database leads should lead to a new row in the HTML table. However I can only get it so the first row from the database goes into the html table as it should, the rest go outside it. Any ideas? Code:

Echoing Users Data From Mysql
when users on my site look at they're profile details some of the data in like this:

<select name="somename">
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
</select>

once a user has selected an option and it's stored in mysql i was wanting the specific information to be displayed in the drop down box, if i selected option 2 next time i log in option 2 is displayed and so on. what would be the best way to achieve this?

Is_dir() And Opendir() - Detecting Sub_directories And Echoing Them?
I am working on a single script to:

1) create a menu of directories containing photos (jump to script below)
2) output all the thumbnails of each photo (linked to photo itself) within each linked directory

I have step 2 solved. However, as I was about to solve step 1, I mucked up my code so badly I lost it. I simply want to output all the sub_directory names within a directory.

my structure is as follows:

../images/photos/group
../images/photos/sports
../images/photos/outdoors
etc.

The script itself is currently located in the images directory but could also be located in the photos directory as I want to detect all sub_directories of photos. Here is the part of the script that is supposed to do what I want in step 1. PHP Code:

Not Echoing A Variable If It Exists In A MySQL Table
I have a variable $mydate which loops for all the days of a month (in a while loop), so therefore for April its:

01042007
02042007
03042007, etc...

I also have a MySQL table "bookings", which contains the field "date". This field is populated with rows of dates, with the same format as those in $mydate (eg. 01042007)
Is there any way to not echo $mydate if it exists as one of the entries in the "date" field in the database?

Multiple Select From Listbox And Execute A Sql Query Select Statement
Supposing i have a html form with 2 listbox and i name it status and resolution.

So it goes <select name='status[]'>... <select name='resolution[]'>

Then i have a another php page.
$status = $_POST['status'];
$resolution = $_POST['resolution'];

Now my question is, how do i do the sql query statement?

mysql_query("SELECT * from bugs where status=$status and resolution=$resolution");

The problem is, i select 3 options form the status listbox eg. new, closed, duplicate. And from the resolution, i chose fixed, invalid.

Select Statement - Select Random ID #
I have made up a page that pull info on 13 branches of stores onto one main page. It's basically there to display all the branches on one page... then you click on the one you're interested in and then you go to a more detailed page.

Back to the main page. On the top, there's kind of a featured branch that has a bigger picture and bigger title but it's still getting pul pulled from the same table etc etc etc.

In order for me to avoid favortism to one branch (and for other branches to start complaining) I want to ramdomized the order every time someone came to page but I have no idea how.

right now I have a super simple select statement.


Copyright © 2005-08 www.BigResource.com, All rights reserved