HOME       >>       Programming

Need Some Help Displaying A Field


ginginca

I run a web site that is a directory of sites in my City. Since submissions are free, I continually receive submissions from webmasters that are NOT at all related. It is of course a waste of time for them ... and a waste of time for me. (Some people just don't take the 30 seconds to read.)

I have decided to add a new field (area code) which will at least help me in quickly identifying the spammers. I was thinking I might even do the same thing with postal code.

I have added a new field to the database, and it is now on my submit page for the "submitters" to fill in.

However, in my admin panel, I need to view this information and that's where I'm running into my question.

It's a very long page of code (which I didn't write myself) so I'm not quite sure how the programmer put it together.

Here is the part of the code that includes the submit vs decline button:

<?$sql="select * from links where other='1' order by date desc";$other_res=mysql_db_query("londonlink", $sql, $sql_conn)or die('Invalid query: ' . mysql_error());for($y=0; $y<mysql_num_rows($other_res); $y++){ $other_info=mysql_fetch_row($other_res); ?> <tr> <td> <?echo $other_info[1];?> </td> <td> <a href="<?echo $other_info[4];?>"> <?echo $other_info[4];?> </a> </td> <td> <? $sql="select * from category where idnum='$other_info[2]'"; $other1_res=mysql_db_query("londonlink", $sql, $sql_conn)or die('Invalid query: ' . mysql_error()); $cat_row=mysql_fetch_row($other1_res); print $cat_row[1]; ?> </td> <td> <? $sql="select * from sub_category where idnum='$other_info[3]'"; $other2_res=mysql_db_query("londonlink", $sql, $sql_conn)or die('Invalid query: ' . mysql_error()); $subcat_row=mysql_fetch_row($other2_res); print $subcat_row[2]; ?> </td> <td> <?echo $other_info[7];?> </td> <td> <input type="submit" name="<?echo "accept".$other_info[0];?>" value="Accept"> </td> <td> <input type="submit" name="<?echo "decline".$other_info[0];?>" value="Decline"> </td> </tr> <?}?>

What I don't understand is how he is making each item in the list appear. There is a list of variables at the beginning of of the page ... but I don't think that is what I am looking for.


/* VARIABLES*/$database['host']="****************";$database['name']="****************";$database['pass']="************";$table[1]="category";$table[2]="sub_category";$table[3]="links";$sql="select * from $table[$num]";$where_sql="select * from ".$table[$num]." where ".$field."='".$opt."'";$submit[1]="add_cat";$submit[2]="name_cat";$submit[3]="old_cat";$submit[4]="add_sub_cat";$submit[5]="name_sub_cat";$submit[6]="old_sub_cat";$submit[7]="add_link";$submit[8]="edit_link";$submit[9]="rem_link";$submit[10]="bansub";$today=date("Y-m-d");

But I think these are only for the various sections of my admin panel. Based on what you see here, what am I looking for? Or do I need to post the entire page?

yordan

do I need to post the entire page?

No, don't post the entire page here, it would make the post hardly readable. The part is posted is enough, if a guy seeing what to do comes here, he will ask you to PM him the program.And, no, I'm not this guy, I'm not skilled enough so I will not be able to help you more.

minnieadkins

I never used mysql_fetch_row. I always use an association or data object.Obviously you areLooping over the links tableThen Pulling from category table.Then pulling from sub_category table.The question is, where is your area code field located? In which table of the database. As far as using the mysql_fetch_row function, I'm not 100% on how the various fields in a row are indexed. I would assume by the order they appear in the DB. Correct me if I'm wrong there.


ginginca

The question is, where is your area code field located? In which table of the database. As far as using the mysql_fetch_row function, I'm not 100% on how the various fields in a row are indexed. I would assume by the order they appear in the DB. Correct me if I'm wrong there.

 


I put it in the links table. The field is called area_code.

 

And yes they appear in order in the web site.

 

As for the admin panel, the most recent is listed first.


minnieadkins

I put it in the links table. The field is called area_code.

 

And yes they appear in order in the web site.

 

As for the admin panel, the most recent is listed first.

 


I guess then next question is, where do you want this to be displayed?

 

I do not know what index the field would be. I assume to will have to look in the database yourself and see what # field your area_code field is in the links table.

 

Replace X with the position that your new area_code field is located at in your database. I assume this would work.

 

For example if your fields are:

ID

NAME

Link

 

X would be 3

 

Throw this data cell in anywhere inside of your loop but after your first mysql_fetch_row function. If it is indeed in your links table then it will be using your $other_info array.

<td> <?echo $other_info[X];?></td>

If you have any problems then feel free to post.

ginginca

I do not know what index the field would be. I assume to will have to look in the database yourself and see what # field your area_code field is in the links table.

Replace X with the position that your new area_code field is located at in your database. I assume this would work.


That "somewhat" has been my question. I didn't understand what those numbers meant. But you have explained it a little. I'll play with that a bit and see if I get any result.

Thanks. I'll let you know if it works or not.

ginginca

Yes this is exactly what I am confused about.

 

Here are my fields in the links table:

 

idnum

name

cat

sub_cat

url

date

status

email

other

area_code

 

 

(other is 0 in every record so I think this is not in use).

 

I don't get how the field names relate to $other_info[x]

 

The code says this:

 

<?$sql="select * from links where other='1' order by date desc";$other_res=mysql_db_query("londonlink", $sql, $sql_conn)or die('Invalid query: ' . mysql_error());for($y=0; $y<mysql_num_rows($other_res); $y++){ $other_info=mysql_fetch_row($other_res); ?> <tr> <td> <?echo $other_info[1];?> </td> <td> <a href="<?echo $other_info[4];?>"> <?echo $other_info[4];?> </a> </td> <td> <? $sql="select * from category where idnum='$other_info[2]'"; $other1_res=mysql_db_query("londonlink", $sql, $sql_conn)or die('Invalid query: ' . mysql_error()); $cat_row=mysql_fetch_row($other1_res); print $cat_row[1]; ?>

The table looks like this:

 

Company Name URL Category Sub-Category Email Address (area code to be here)

Company Name URL Category Sub-Category Email Address (area code to be here)

Company Name URL Category Sub-Category Email Address (area code to be here)

 

The most recent on the top of the list was the last one submitted.

 

Then on the right side, there's a choice of two buttons - reject or approve.


vujsa

<?$sql="select * from links where other='1' order by date desc";$other_res=mysql_db_query("londonlink", $sql, $sql_conn)or die('Invalid query: ' . mysql_error());for($y=0; $y<mysql_num_rows($other_res); $y++){ $other_info=mysql_fetch_row($other_res); ?> <tr> <td> <?echo $other_info[1];?> </td> <td> <a href="<?echo $other_info[4];?>"> <?echo $other_info[4];?> </a> </td> <td> <? $sql="select * from category where idnum='$other_info[2]'"; $other1_res=mysql_db_query("londonlink", $sql, $sql_conn)or die('Invalid query: ' . mysql_error()); $cat_row=mysql_fetch_row($other1_res); print $cat_row[1]; ?> </td> <td> <? $sql="select * from sub_category where idnum='$other_info[3]'"; $other2_res=mysql_db_query("londonlink", $sql, $sql_conn)or die('Invalid query: ' . mysql_error()); $subcat_row=mysql_fetch_row($other2_res); print $subcat_row[2]; ?> </td> <td> <?echo $other_info[7];?> </td> <td> <input type="submit" name="<?echo "accept".$other_info[0];?>" value="Accept"> </td> <td> <input type="submit" name="<?echo "decline".$other_info[0];?>" value="Decline"> </td> </tr> <?}?>
Replace That with This:
<?$sql="select * from links where other='1' order by date desc";$other_res=mysql_db_query("londonlink", $sql, $sql_conn)or die('Invalid query: ' . mysql_error());for($y=0; $y<mysql_num_rows($other_res); $y++){ $other_info=mysql_fetch_row($other_res); ?> <tr> <td> <?echo $other_info[1];?> </td> <td> <a href="<?echo $other_info[4];?>"> <?echo $other_info[4];?> </a> </td> <td> <? $sql="select * from category where idnum='$other_info[2]'"; $other1_res=mysql_db_query("londonlink", $sql, $sql_conn)or die('Invalid query: ' . mysql_error()); $cat_row=mysql_fetch_row($other1_res); print $cat_row[1]; ?> </td> <td> <? $sql="select * from sub_category where idnum='$other_info[3]'"; $other2_res=mysql_db_query("londonlink", $sql, $sql_conn)or die('Invalid query: ' . mysql_error()); $subcat_row=mysql_fetch_row($other2_res); print $subcat_row[2]; ?> </td> <td> <?echo $other_info[7];?> </td> <td> <?echo $other_info[9];?> </td> <td> <input type="submit" name="<?echo "accept".$other_info[0];?>" value="Accept"> </td> <td> <input type="submit" name="<?echo "decline".$other_info[0];?>" value="Decline"> </td> </tr> <?}?>

You will NEED to adjust your table header by adding a header for areacode.

To help you better understand you table fieds in relationship to the array they are in in PHP, here are the array keys for each field:

[0] - idnum
[1] - name
[2] - cat
[3] - sub_cat
[4] - url
[5] - date
[6] - status
[7] - email
[8] - other
[9] - area_code


Hope this helps.

vujsa

ginginca

It works beautifully. Thank you!

I had already added the header ... I was just confused about the data to sit underneath.

To help you better understand you table fieds in relationship to the array they are in in PHP, here are the array keys for each field:
[0] - idnum
[1] - name
[2] - cat
[3] - sub_cat
[4] - url
[5] - date
[6] - status
[7] - email
[8] - other
[9] - area_code


Is this just taking them in the sequence that they are in the table? Or is there something else that is defining the number?

vujsa

It works beautifully. Thank you!
I had already added the header ... I was just confused about the data to sit underneath.
Is this just taking them in the sequence that they are in the table? Or is there something else that is defining the number?


There wasn't anything in your code that specified the order of your fields so by default, the array would populate based on the order that the fields appeared in the database table.

This is a rather confusing method of programing since it doesn't really offer end users the chance to easily modify the code.

It is entirely possible that the following will work:
<?echo $other_info['area_code'];?>

I usually use mysql_fetch_array() instead of mysql_fetch_row() so it is hard for me to say for sure.

You could give it a try! It wouldn't really hurt anything since it doesn't alter you database. If it doesn't work, just change it back.

vujsa

minnieadkins

Nice, glad to see it's resolved. Good to see you posted all the fields in the database in the order they appear. That was the key.

I personally do this

while($row = mysql_fetch_assoc($qh)){echo $row['area_code'];}

You could also join your tables together and have one query to do all your pulling for you rather than accessing the database three times.

ginginca

<?echo $other_info['area_code'];?>
vujsa

Doing it this way would have made more sense to me.

But thank you for helping me out. I'm new to PHP and have soooo much to learn!

Gin


VIEW ORIGINAL REGISTER GET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.