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




Dynamic List Items Repeating Themselves


I'm working on this online magazine, and each page (well, other than the front page) has a menu included on the right-hand side consisting of articles divided into three sections: articles, columns, reviews. For some reason, whenever I click on one of these article links, that link takes the place of the first link in the section. You can see what I mean here: PHP for the included right_menu.php PHP Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Deleting Items From A List
When i click one of the delete buttons, the form submits, but nothing happens. I'm pretty sure i'm doing something stupid with the form buttons, but I've been staring at it too long...any takers? Code:

Dynamic Form Items
I am trying to create A form that its fields will depend on a
form menu.
for example.
/***********************************************/
<form name="form1" method="post" action="">
<select name="select">
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
</select>

Text field 1<input type="text" name="textfield">
Text Field 2<input type="text" name="textfield2">
Text Field 3 <input type="text" name="textfield3">
Text Field 4 <input type="text" name="textfield4">

<input type="submit" name="Submit" value="Submit">
</form>
/***********************************************/
When the option 1 is selected only the textfields 1 and 2 to appear,
when option 2 is selected only textfields 1 and 3 to appear and so on... any
combination I would like.

I tried puting the textfields in "if" statments but i don't like it. its too
messy PHP and HTML code.
Any Ideas of how this could be done better ? If someone did something
similar before and has a relative link it would be good as well.

Adding Items To A List Or Menu
Not sure if it is a php question but since i am working in php here it is.

Ho can i add items to (the item label=visual text and the value=index
number) a list object on a website.

I am having a list with 4 items and i would like to add the text from a
textfield (textfield1.value) to the list object so it will hold 5 items.

Adding List Items To A Database
Not sure if this is javascript or php so i put it in both newsgroups, sorry
if it's the wrong group.

I wrote (with help) a code to put several items in a list object (select)
and I would like to add the items in this list to a database.

I know how to add a selected item to the database but how can i put al the
items tot the database. I need somekind of loop wich go's through the list.

Grabbing A Random List Of Items, One Per Line?
what I want to do though is search these lines of data, line by line, and grab a random word from each line, until a reach a limit. So far I have this, Code:

A Dynamic Drop Down List
I need to create a dynamic drop down list. By this i mean that the webpage html form = select style will recieve all the values as based on a query to a mysql database. I have no problems quering the data base with PHP, But i need to make some kind of for loop that will add a new value to the selct form for each result from the database. my thought process go like this.

1. call data base to guery. (no problem)

2. make variable variables that will be created according to the number of results (these variables must be created according to results of query, not a problem i think)

3. make a form like this

<form action = ***** method = post>
<select name = ******>
<option value = "This is a query result"> This is a query result> //This is the part i need to using a for loop and variable variables
</select></form>

so my problem is part 3, cause is this all done in PHP, or if i had all these variables, can i do this in HTML? Can i make a for loop in PHP that would break into HTML during these parts?

Dynamic Mailing List?
I have a schedule of people that need reminders sent to them weekly.  I have figured out how to set a Crontab to send the reminder automatically ... but the people are not the same every week.  I know that I could build multiple scripts and hard code the email addresses, setting a cron job for each - but is there any way to build ONE script that will read a text file based on the date and pull the names/email addresses off of that? 

Dynamic List Order
I was trying to get the list box to display the id numbers in ascending order however the code below does not work, just wondering how to fix it?

<?php
$g = "SELECT * FROM em ORDER BY iD ASC";
$q = mysql_query($g, $link_id) or die(mysql_error());

if (mysql_num_rows($q) > 0)
{
?>
<select name="d">
<?php
while($r = mysql_fetch_assoc($q))
{
?>
  <option value="<?php echo $r['Id']; ?>"><?php echo $r['Id']; ?></option>
<?php
}
}
?>

Dynamic List Population
how do you populate a list dynamically? for example I have the following in a table but I can't get them into the list after the query is performed.

<form action="">
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>

Generating A Dynamic List
I am tying to write a statement that will compare the values of 2 columns, and display the result in a temp table.

ex. Table A has the following columns: "Minimum" and "Maximum." The temp table will hold the reult of the difference between the 2 columns of table A.

Scope: I am trying to crate a drop down with the resulting data as it is incremented. If Min = 2 and Max = 7, the TEMP tab;e should get the results of 2,3,4,5,6,7. I want to have this result displayed in a drop-down list.

Dynamic Checkbox List - DB Update
I have a set of questions which are being dynamically output:

for($i=0; $i<count($question_array); $i++)
{echo $question_array[$i][question] .

"<input type='checkbox' name='question_" . $question_array[$i][id] . "' value='Y'' . "><br>";}

I then want to update each question in the DB. I want to loop through each question id and carry out the relevant action (either enable or disable). What is the best way to do this?? As I am dynamically generating the variable name (e.g. question_50) what is the best way to loop through these updating the relevant id?

Dynamic Drop-down List In Array
Q. How do I create a dynamically-generated drop-down list for use in
an array.

I'm using PHP with a MySQL database (through phpMyAdmin)

My database table is called com_courses, and I want to pull the
distinct 'title' fields and have them appear as a drop down menu for
the user to select in a form.

Here is my array, with (at the moment) manually-entered 'titles'
(which I now need to be dynamically generated from my database field:
'com_courses.title'

array (
"coursetitle",
"Course Title:",
$EXTRA_SELECTLIST,

array ("Report Writing", "Recruitment & Selection", "Presentation
Skills", "Essential Telephone Skills", "Time Managememt", "Customer
Care", "Other"),
0
),

I am not an experienced programmer, but can play around with php to
customize programs. I've read up on arrays (I bought a "Programming
with PHP and MySQL" book, but it just stops short of this problem). I
can't figure this one out.

The Dynamic Zone Of List PHP. Please It 's Very Urgent!
I want to create in a form in php two zone of list (A and B).
the options of the zone lists B are dependent on the option chosen in
zone A.

Dynamic Form Option List
I want to create a dynamic drop down option list in a form, but I just can't wrap my head around this.

Both of the below scripts work as intended, but how do I make the mySql query results work with my existing script?  Yes, I know I must replace the "$options = array" part in the top piece of code, but I need a little more guidance than that. Code:

Searching Dynamic Driven List
I have a members database will all their personal details in. I have a page running a SQL query to display a complete list of all these people. This is what my query looks like:

$sql_prop = "SELECT * FROM $db.members WHERE area = '".$_REQUEST['area']. "' ORDER BY name ASC;
$result_prop = mysql_query($sql_prop) or die(error_report("Mysql Error", mysql_error()."

$sql_prop", $_SERVER['REMOTE_ADDR']));

"Error Report" is just one of my functions. I have two forms fields on this page, "Name" and "Address". I want to be able to search the listing that this SQL query has returned for those fields, ie. the user enters "John" in the form field and it returns all entries within the query matching "John". The reason I'm using this:

area = '".$_REQUEST['area']. "'
in the WHERE clause, is just to ensure that the person viewing this list can only see members that are in his area. On the previous page there is a piece of code that gets the session "area" and brings it across to this page. I'm keen on keeping that code in. It works for me at the moment.

Any ideas? How can I search this already filtered list?

Dynamic Form - How To Set Values Of A List
I have a form with a list/menu in it that is populated with records from a database. The items in list#2 are based upon what is selected in list#1.

I have been able to use a combination of php and javascript to get it to work, but the javascript reloads the page to get list #2 to refresh - and that clears out any other fields that have been filled in. Instead of javascript being called for the 'onchange' event for list #1, I'd rather it call php when list#1 is changed and so reset the values in list#2.

OPTIONS:
1. I thought I could have a php function that is called (i.e.   onchange="<?php reload();?>" but I can't figure out how to set the values of the list from within the php function. How to reference form objects with php?

Dynamic List Populated By MySQL Table
I am building my first php page and I've ran into problems trying to create a dynamic drop down list for an INSERT page. My page is based on this example from mysql.com.

I want to populate the list from a table in MySQL, but when I test the page the list only contains the first record. If anyone can help me out, or recommend an easy way to create dynamic menus/lists, I will be very grateful.

This code appears above the FORM ACTION:

$NearMajorCity = mysql_query("SELECT NearMajorCity_ID, NearMajorCity FROM NearMajorCity");

This code is within the FORM:

<SELECT NAME="NearMajorCity" SIZE=1>
<OPTION SELECTED VALUE="">Select One
<OPTION VALUE="">---------
<?php
while ($NearMajorCity = mysql_fetch_array($NearMajorCity)) {
$NearMajorCity_ID = $NearMajorCity["NearMajorCity_ID"];
$NearMajorCity = $NearMajorCity["NearMajorCity"];
echo("<OPTION VALUE='$NearMajorCity_ID'>$NearMajorCity
");
}
?>
</SELECT>

I want to be able to view the names of the Major Cities in the list, but I want the NearMajorCity_ID inserted into the table.

Member Area With Dynamic File List
I have an Apache 1.3.31 with PHP 4.4.1 available and want to create
some kind of "member area" with a per-user or per-group listing of
files that can be downloaded.

How would I do this?

At present I just protect the individual files using .htaccess
and .htpasswd files and give out direct URLs to the files together with
username/password. What I'd like is some login functionality where
people can log in using their username/password and then find a list of
files they can download together with additional information
individually tailored for that user.

Dynamic Drop-down List With Array - Question
Can anyone out there give me a pointer regarding creating a
dynamically-generated drop-down list connected to an array?

And is that question as clear as chocolate spread?

Here's what I've got. I'm using PHP and MySQL database. I'm customizing
some calendar software, and I want the user to fill in a form by
selecting a title from a drop-down list, generated by my MySQL
database. However, the program I'm customizing uses arrays, which is
where I'm stumped.

What do I need to add to this code to make the array of titles(eg
"report writing" etc) come from my database, rather than the
manually-entered values that you can see here.

The field I want to pull from is called com_courses.title

array (
"coursetitle",
"Course Title:",
$EXTRA_SELECTLIST,

array ("Report Writing", "Recruitment & Selection", "Presentation
Skills", "Essential Telephone Skills", "Time Managememt", "Customer
Care", "Other"),
0
),

I hope it's not cheeky to ask this,
BTW I bought a book on Programming with PHP and MySQL, but it doesn't
answer this question,

Random $var Repeating.
I'm trying to pull random lines from text file and print them from calling a variable but everytime I call the variable it pritns the same thing. Here is the code:

<?php
$var = file("vars.txt");
$returns = array("", "");
$var = str_replace($returns, "", $var);
foreach ($var as $num=>$line) {
$var[$num] = strtolower("$line");
}
$n = sizeof($var ) - 1;
$var = $var[rand(1, $n)];

echo $var;
echo $var;
echo $var;
echo $var;
echo $var;
echo $var;

?>

This prints:

line3
line3
line3
line3
line3
line3

When I want it to print each line randomly, like:

line9
line2
line6
line2
line1
line6

Any changes you can see in that code?

Repeating Tables
I am trying to create a image gallery based on a tutorial found on http://www.php-mysql-tutorial.com/image-gallery/ and I need to put image, title and desc in seperate rows so they are aligned and not wonky if one has more text than the other but can not seem to get it. Code:

Repeating Table
In firefox the tables stack side by side until they reach the edge of the table they are nested in then they start a new row of tables on the next line. In IE the tables continue to populate 1 single line inspite of the fact that the user cannot see them. Code:

Function Repeating When Called?
I have this function set to call when a form is successfully submitted. Basically it's supposed to display a confirmation/thanks message and the results of their form input. The problem is:

1. it's repeating itself in the display (See below for example)
2. I'm getting this 'invalid query' message for the 'while' function

Here's the function code:

Auto Repeating Script
I was wondering if there was anyway of running a external php script every 30 seconds pretty much infinitely. If possible without having to leave my computer on 24/7.

Any idea how I could do this?

Looping/Repeating Part Of A Script
Can someone point me in the right direction either for the logic or maybe the function, here's what Im trying to do.

I would like a script to run a particular function "X" times based on what a user inputs via a form. So,

(excuse the coding, Im just trying to show what Id like it to do, I will fix it up later)....

Strange Inconsistences When Repeating A Query More Than Twice In A Row
Here is a small sample program I wrote in PHP (running off Apache
1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data
base is using DB2 V5R3M0. The client is WinXP machine using the iSeries
Client Access Driver ver 10.00.04.00 to connect to the database.

The problem is that executing the exact same SQL select statement more
than twice int a row stops produces results. The first two instances
will always produce the correct results but after that it will simply
return with no results found. I've also wrote the exact same test case
with other various ODBC APIs with the same results.

I've examining the ODBC driver trace log and I am unable to find any
noticable differences between a SQL statement producing the correct
results and one that produces a no results found message. I've tried
three different ODBC driver versions and have the same results.

NOTE: This doesn't occur for EVERY select statement but it does occur
for different files with various WHERE clauses but I've been unable to
determine any relationship between working and non working repeating
select statements.

PHP SOURCE CODE:

Simplifying Repeating Database Connections In A Class?
I wrote my first PHP class today. Yeah!
But to get it to work, in each function within the class I have to
repeat the database connection lines, and that just seems redundant;
there has to be a better way that I'm just not bright enough to think
of.

(It's the first 3 lines of each of the two functions below. When I have
it fully written, there will be about 10 similar functions, each
repeating those three lines.)

class e_test {

function gettech() {
include('../Connections/userDBconnect.php');
$db = mysql_select_db("printing", $connection) or $error .= "Could
not select database1: " . mysql_error()."<p />";
$dbconn = $connection;
// CREATE TECH ARRAY
$sql_T = "SELECT email FROM tbl_users WHERE dept = &#391;' AND
active=&#391;'";
$result_T = @mysql_query($sql_T, $dbconn) or $error .= "Could not
query1: " . mysql_error()."<p />";
$count_T = mysql_num_rows($result_T) or $error .= "Could not select
query2: " . mysql_error()."<p />";
$i_T = 0;
while ($row_T = mysql_fetch_array($result_T)) {
$email_T = $row_T[email];
$techs .= $email_T;
$i_T++;
if ($i_T < $count_T) {
$techs .= ",";
}
}
echo $error;
return $techs;
}

List Contents Of A Folder, Make List Of Links
Does anyone know how I can write a script that:

- reads in all the files in a particular directory
- displays the file names in a html list and makes a link of them:
<ul>
<li><a href="filelocation1">filename 1</li>
<li><a href="filelocation2">filename 1</li>
<li><a href="filelocation3">filename 1</li>
</ul>

etc.?

So basically it creates a list of links with the contents in that directory,
so you can download them from there.

Get List Of Messages From One Table, Message List Indicator From
I have two tables. One has a list of messages left by users using fields named mbxno for the mailbox and msgno for the message number. I have another table that has mailbox settings for each user that contains a field named "messagelist" to indicate if they want to be included on the message list or not.

What I'm trying to create is a list of the most-recent messages with a lookup on the users table to indicate whether a message in the list should be included in the message list based on the user's mailbox settings.

SELECT messages.msgno, messages.mbxno, users.messagelist FROM messages, users WHERE (users.messagelist = &#391;') ORDER BY msgno DESC LIMIT 100

What I'm getting, though is a list that looks like this:

mbxno: 1114 msgno: 0412141623 msglist: 1
mbxno: 1114 msgno: 0412141623 msglist: 1
mbxno: 1114 msgno: 0412141623 msglist: 1
mbxno: 1114 msgno: 0412141623 msglist: 1
mbxno: 1114 msgno: 0412141623 msglist: 1
mbxno: 1114 msgno: 0412141623 msglist: 1
mbxno: 1114 msgno: 0412141623 msglist: 1
mbxno: 1114 msgno: 0412141623 msglist: 1

I think what's happening is that I'm using the wrong type of join and more rows are being created than necessary.

If I add "DISTINCT" to the query, I get a list of the most-recent messages as I expect, but the "messsagelist" value is sometimes wrong (again, probably because the data is getting jumbled). For example, the messagelist value for the second row (2214) should be 0, not 1.

mbxno: 1114 msgno: 0412141623 msglist: 1
mbxno: 2214 msgno: 0412141622 msglist: 1
mbxno: 2189 msgno: 0412141408 msglist: 1
mbxno: 0000 msgno: 0412141213 msglist: 1
mbxno: 0003 msgno: 0412141213 msglist: 1
mbxno: 2265 msgno: 0412132029 msglist: 1
mbxno: 0000 msgno: 0412131950 msglist: 1

How should I be doing this? If nothing else, what kind of join will work with a long list compared to a value from a short list?

Populating A List Box Or A Dropdown List Using Php And Odbc
I need to populate a list box and/or a dropdown list on a form. I have all
the bits and pieces together, all bar the code which takes the result of a
query and creates a list box.

Mailing List Manager, Send To List
I'm looking for a mailing list script (php) that has a function to let
users to reach out to all recipient on the list by simple send the
email to a specific maillist- address.

Mailman has this functionn but as a just got a webserver account I
can't use mailman nor install it.

Related Items
I noticed a lot of websites show "Related Items" on each product page. I want to know how usually do you implement it. Should I add a field in the mysql table to hold the "Related Items" information? What's the best solution?

Get ID Of Deleted Items
I wonder if there is anything similar to "mysql_insert_id();"
for deleted/updated id's?

If i do a query and DELETE WHERE text_field="",
can i get the id's of the fields that were deleted?

How Many Items Are In An Array?
I dont know how many values there are in my array after it's been split.. is there a command? array_count_values doesnt do what I need sadly.

Add/Delete Items
I have the following code, that displays a message whether a users shopping cart contains items or not. How do I add/delete items from the shopping cart, upon the appropriate product link being clicked? If a items is already in the cart, how do I display a message notifying the user? Code:

Favorit Items
i have many tables with different data structure due, am  making a service which will allow users to add itimes to thier "favorit items" tables
I thinked to use the table names as a hidden filed, like if the table name is "hotel" and the user added a hotel to his favorit items , the hidden fild will be hotels, and then pass that field as a variable then use it in a query to get the hitel data, does this adea work? or there is a better way ?

Using If Empty With Two Items
I am trying to say if $_Post and $_Session are empty set the variable $dcparent to equal 1, but it doesn't like what I am doing. 

if(isset($_POST['dcparent'])) {
$dcparent = mysql_real_escape_string($_POST['dcparent']);
}

if(isset($_SESSION['dcparent'])) {
$dcparent = mysql_real_escape_string($_SESSION['dcparent']);
}

if(empty($_POST['dcparent']) && (empty($_SESSION['dcparent'])) {
$dcparent = 1;
}

Multiple Cart Items
I've created a shopping cart application using php 4.06 and postgres. a problem i had was that when i added the same item twice it was adding an extra item as opposed to adding the quantities together. i did manage to sort this out to an extent but my only solution means using a block of code for each item which has made my script very long and i'm pretty sure has made the script somewhat unreliable. I would appreciate it greatly if someone could offer a solution to this, this is my code for adding items to the cart: PHP Code:

Finding @ In A String, And Other Items
Ok - I want to check a string for @ in it (Im checking to see if a string
that should contain an email holds a @ )

How would I go about this? preg_match? ereg? strstr? Examples?

Also - how would I find any non alpha numeric characters in a string so I
can give the user an error message. I dont want any characters besides
alpha-numeric in the strings.

Multiple Items Of Same Name In Session?
I have a shopping cart where I can add tshirt designs to the cart. The designs are added to a php session object called cart. The object 'cart' consists of the design name, color and the quantity.

The probem is that if someone adds the same design to the cart again then it just increments the quantity of the existing design with the same name instead of adding another instance of it to the cart. How can I have multiple instances of the same design with the same name in the cart at the same time.

One thing I thought of was to append some sort of incrementing id to the design name before it is added to the cart. Thus the next time the design is added it would have a new id appended and the resulting name would be different.

Number Of Items In A Cart
I am working with a session and a 'cart' (note that I do not really know what I am doing though).

I was wondering if there is some easy way (function) to work out how many items I have in my 'basket' / 'cart', because then I could
call this function from anywhere to show the user just how many items are on order



Only Allow X Number Of Items To Be Checked
I have a function that renders out tag categories, and then all the tags within said category. Each tag has a checbox beside it, i am wondering if it's possible to only allow a user to check 4 tags. Here is the function: Code:

Display Items Using Checkbox
i have a page where in it lists all job items on a table and each item has a checkbox
so when i check one or more items when i click the post button it should display the job items on this post page. my problem is, my post page is not working. Code:

Count Of How Many Items Are In Database
I am wanting to create an select menu for displaying the order of the item
on a page. I am guessing that I need to get the count of how many items are
in the db and them put them into a select menu.

Does anyone know how to do this or can point me in the right direction?

Display All Array Items
How do I display all the items within an array? Also, how do I delete a particular item from an array?

Changing Items After A Date
What I have is a table (code below) and it is for an events page. What I want is after the date has gone, it changes the whole row to grey. ( #666666 ). Code:

Multiple Items In Foreach()
Can someone tell me what im doing wrong with the code bellow please? I get print_ticket called lots of times, with 1 as the hash,name,ticket_no responce.

(i have chequed that the query is returning the right results).

$return = pg_query($pg_connection, $query);
        $data   = pg_fetch_array($return);                   

foreach ( $data as $temp ) {
   
echo print_ticket ($temp['hash'],$temp['name'],$temp['ticket_no']);   
}

Compare Items In An Array...
I have been getting on fine with basic coding until I stumbled accross a problem. I cant seem to figure out how to check to see if a value in one array is in another array - and if so just simple report back "true" or "false".

Lets call the two arrays LOCKS and KEYS. Doing a print_r($locks) would give: Code:

Seperating Search Items
When conducting a php sql search i get some great results, however i want to expand my results so that when multiple search terms are added it will display all relevant fields.

$query = "SELECT * FROM Mixes WHERE dj LIKE '%$var%' OR event LIKE '%$var%' OR tracklist LIKE '%$var%' OR date LIKE '%$var%' ORDER BY event ASC";

From the above search i can only get single results from 1 field. I want to be able to seperate the search term into individual items that can be referrenced in the database.

So for example i search for a dj name and also an event they play at i get zero results, however if i search for them individually i get the results i want.

How do i expand the code to display the result of both the dj and the event or any of the other fields?

I presume that i need to be able to set each search item into an individual variable and then use them to search.


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