ID vs Name

Hi all

This is my table fields
id
name

id is primary key

I listed names in index.php


<a href='".$row['name']."'><font color='yellow'><b>View Profile</b></font></a><br/>

when select that link its look like localhost/polte/name

its working fine but main problem is when I enter same names mean (rao its id 1 and another rao id is 2) the name are display in index page when i select that names I am getting data same from only id from 1 what is the problem

please give any suggestion to me.

If the name is not unique, why don’t you use the id in the link?

guido2004 thank u for replay.

yes name is not unique. I used to display, when visitor select the name that will display the

babynames on url like localhost/polite/munna (I used .htaccess for display name on url) munna is a name

any suggestion please

If the name is not unique, how are you going to decide which ‘rao’ I clicked? Or do you want to show the data from all 'rao’s when one is clicked?

I am new for php and sql

I used this one in my table


name VARCHAR(50) UNIQUE,

but not allowing duplicate entries how can i use unique id

thank you once again replay here

If names are not unique, you can use that attribute to pass array, such as “a”, or whatever…
See examples here.

the Rao are different person names. But they have same names Rao one had id 1, Rao second person had id 2, when i select in list any Rao that displaying first rao information can you understanding my explanation guido2004.
The main concept is visitor can add their baby names in the my babypage some body have same names, like Rao how can I improve this one to display the information

My question is what info do you want to display?

If you have Rao (id 1) and Rao (id 2) and you click on Rao (id 2), what info do you want to display? The info from Rao (id 2)? The info from both Rao’s ?

If you want to display the info from Rao (id 2), then my second question is:

How can your script know that it must show the info from Rao (id 2) and not Rao (id 1)?

thank u once again

Ok, I am posting my all codes

this is my list page code


<a href='".$row['bname']."'><font color='yellow'><b>View info</b></font></a><br/>

I used to display for names as url
.htaccess


RewriteRule ^([^/\\.]+)/?$ 2get_kids_list.php?babyid=$1 [NC,L]

info list code


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta http-equiv="imagetoolbar" content="no" />
	<title>FancyBox 1.3.4 | Demonstration</title>
	</head>

	<body>


<div id="wrapper">
       
	<div id="content">


<?php
// get babyid
$bname= addslashes(strip_tags($_GET['babyid']));

$host="localhost"; // Host name
$username="root"; // Mysql username
$password="xxxi"; // Mysql password
$db_name="kids"; // Database name
$tbl_name="ca_kids"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect to server ");
mysql_select_db("$db_name")or die("cannot select DB");

$sql=("SELECT * FROM $tbl_name WHERE  bname = '".$babyid."'");

$result= mysql_query($sql);
$rows=mysql_fetch_array($result);
$bname = mysql_escape_string($rows['bname']);
$fname = mysql_escape_string($rows['fname']);
$mname = mysql_escape_string($rows['mname']);
$age = mysql_escape_string($rows{'age'});


$result1=mysql_query($sql1);


echo  '<tr>  </tr>
<table  width="100%" border="0" cellpadding="0" cellspacing="0">
  <tbody>
    <tr>
      <td colspan="2" class="secondtableheadtd" style="color: rgb(255, 255, 255);" align="center" background="../images/tab-bg.png" height="20"><font size="3" color="white">'.$rows['bname'].' || Hits:'.$rows['count'].'</font>
	  </td>
    </tr>
</tbody>
</table>

<table  width="100%" border="0" cellpadding="0" cellspacing="0"> 
<tr>
<td bgcolor="#ECF1EF"><a href="home.php"><font size="3" color="red"><b>Home</b> || <a href="add_kid.php"><font size="3" color="red"><b>Add-School</b></a></td></tr>

</table>

';


echo '<table align="left" cellspacing="5" cellpadding="5" bgcolor="#ECF1EF" width="100%" border="0">
<tr><td rowspan=9 bgcolor="" align="left"><img src="http://localhost/polite/kids/images/' . $rows['image'] . '" alt="No Image" width="370" height="250" border="2px" bordercolor="white"></td></tr>

</table>

<table align="center" cellspacing="5" cellpadding="5" bgcolor="#ECF1EF" width="100%" border="0">
<tr>
      <th colspan="2" bgcolor="#2F4F4F" align="left"><font size="2" color="white">Child Information</font></th>
    </tr>
<tr><th align="left" width="90px" bgcolor="#FFFFFE">Child Name</th> <td>'.$bname.'</td></tr>

<tr><th align="left" width="90px" bgcolor="#FFFFFE">Father Name</th> <td>'.$fname.'</td></tr>

<tr><th align="left" width="90px" bgcolor="#FFFFFE">Mother Name</th> <td>'.$mname.'</td></tr>

<tr><th align="left" width="90px" bgcolor="#FFFFFE">Age</th> <td>'.$age.'</td></tr>
';

echo '<table align="left" cellspacing="5" cellpadding="5" bgcolor="white" width="100%" border="0">
<tr><td>
</table>
';
mysql_close();

?>

</div></head></html>


Why don’t you answer my questions?

You always get the info for the first Rao because you retrieve only the first row from the mysql result set. If you want both of them, use mysql_fetch_array in a foreach loop. If you don’t know how to do that, see the examples in the manual.

I already used mysql_fetch_array no problem I am getting in list both of rao’s

My question is what info do you want to display?

I want to display both rao’s info
name, fname, age, location etc.

I already told the rao’s are different added person names. when select first rao only display first rao info, when i select second rao name display IInd rao info (but here i am getting Ist rao info) and when used different name its working fine

when i used bname on code not getting corect info. But i used babyid i am getting correct info of both

How can your script know that it must show the info from Rao (id 2) and not Rao (id 1)?

i used where bname=$babyid getting for babyid

sorry for troubling and sorry for my English

Don’t worry about troubling, and don’t worry about your english. Slowly slowly we will find the solution :slight_smile:

The problem is the name isn’t unique. When you click on the second Rao, the query in your script gets all rows with that name, but then you only use mysql_fetch_array once, so you always get only the info from the first Rao.

The script cannot know which Rao you clicked. Impossible. That’s why you need to use a unique key. So you can:

  1. Make sure each name is unique: only 1 Rao can exist in the table.
  2. If 1 is not possible, then you must use the id in the url, and change the query so you use the id to extract the data.

guido2004 Thank U very much.

OK. If not possible with name i will go for use Id

thank u once again

shekargoud

Guido, i think Rao would be the last name. Is that correct Shek? You want to display the last name then click for all the full ones?`

No rao is not last name rao names are different names.
ist rao id is 1 and IInd rao Id is 5 or any id. when I select IInd rao (id=5) I am getting Ist rao data.

any one know that logic

thank U replay here.
shekargoud

Can you give an example of the name you are talking about?

I would like to code for kids page. visitor can upload their kids names and photo.

first person uploaded in name of their child name is munna its id - 1 another person uploaded their child name has munna its id is - 10


ID | NAME

1 | MUNNA

2 | BHANU

.
.
.

10 | MUNNA

when I select id of 10 (munna) I am getting data of id -1 (munna) data

then you need to call based on ID not the name?
Use Id vs bname in your code that you used in post 9, your rewrite should still work

post #9 that working fine for all different names when i have same names I have troubling with that code.

to call based on ID its working perfectly. is it possible call name?:confused:

Calling name in your code will fetch the first (or last depending on your sql) record with that name and apply it uniformly across the board. if you use teh Id you get around that, and you can set up url rewrites to make the url be pretty vs id=14